如何使用现有数据帧中的for循环创建动态数据帧

时间:2018-12-20 03:04:19

标签: python

我有这个数据框:

enter image description here

import React, { Component, Fragment } from "react";

class App extends Component {
  constructor() {
    super();
    this.state = {
      twoDimensionalArray: [
        [3, 4, 2, 4],
        [2, 1, 5, 7],
        [5, 3, 3, 2],
        [3, 6, 1, 5]
      ]
    };
    this.printMatrix(this.state.twoDimensionalArray);
  }

  printMatrix = arr => {
    arr.forEach(sub => {
      sub.forEach(item => {
        console.log(item);
      });
    });
  };

  render() {
    return <Fragment />;
  }
}

export default App;

我期望的输出是:

enter image description here

1 个答案:

答案 0 :(得分:0)

我可以使用字典来解决它。

DC = {}

for city in list_city:
    DC[city] = DF[DF['City'] == city]

是否有其他方法可以形成动态变量,例如。 df_(动态名称)在for循环中形成动态数据集。

相关问题