请帮我创建一个简单的数据框,每列中都有行号

时间:2016-10-20 17:07:47

标签: python pandas dataframe

如何在不输入列表的情况下以更大的比例生成此数据框?

pip

谢谢!

1 个答案:

答案 0 :(得分:1)

You can use np.repeat with reshape to get the final df you desire, this will be more efficient and less typing than your current solution:

In [17]:
df = pd.DataFrame(pd.Series(np.repeat(np.arange(5),5)).reshape(5,-1), columns=list('abcde'), index=pd.date_range(start='2000-01-01',periods=5))
df

Out[17]:
            a  b  c  d  e
2000-01-01  0  0  0  0  0
2000-01-02  1  1  1  1  1
2000-01-03  2  2  2  2  2
2000-01-04  3  3  3  3  3
2000-01-05  4  4  4  4  4