df2= pd.DataFrame(df1.iloc[:, [n for n in random.sample(range(1, 7), 3)]])
^{pr2}$returns df1 rows and selected columns but it returns a generic index 0,1,2,3..etc instead of returning the Datetime index of df1 which is what I want to keep. I tried:
但它不起作用。。。在
试试这个:
这会得到你想要的结果。在
^{pr2}$这将随机抽取列的样本并在df2中返回它们。这将返回具有索引的随机抽样列的所有行,如df1中所示。在
编辑- 正如MaxU所建议的,您可以简单地使用:
而不是打电话给pd数据帧()构造函数。在
稍微不同一点的方法呢?在
相关问题 更多 >
编程相关推荐