我是Python和熊猫的新手。我正在尝试将包含一列的所有行放入列表的每个索引中
这是我的密码
result = pd.concat(result, axis=1).fillna(method='bfill').fillna(method='ffill')
打印输出就像
1 2
0 0.57 739.679993
1 0.57 739.679993
2 0.57 739.679993
3 0.57 739.679993
4 0.57 739.679993
5 0.57 739.679993
6 0.57 739.679993
7 0.57 739.679993
8 0.57 739.679993
9 0.57 739.679993
10 0.57 739.679993
11 0.57 739.679993
12 0.57 739.679993
13 0.57 739.679993
14 0.57 739.679993
15 0.57 739.679993
16 0.57 739.679993
17 0.57 739.679993
18 0.57 739.679993
19 0.57 739.679993
20 0.57 739.679993
21 0.57 739.679993
22 0.57 739.679993
23 0.57 739.679993
24 0.57 739.679993
25 0.57 739.679993
26 0.57 739.679993
27 0.57 739.679993
28 0.57 739.679993
29 0.57 739.679993
... ... ...
121571 0.72 738.000000
121572 0.72 738.000000
121573 0.72 738.000000
121574 0.72 738.000000
121575 0.72 738.000000
121576 0.72 738.000000
121577 0.72 738.000000
121578 0.72 738.000000
121579 0.72 738.000000
121580 0.72 738.000000
121581 0.72 738.000000
121582 0.72 738.000000
121583 0.72 738.000000
121584 0.72 738.000000
121585 0.72 738.000000
121586 0.72 738.000000
121587 0.72 738.000000
121588 0.72 738.000000
121589 0.72 738.000000
121590 0.72 738.000000
121591 0.72 738.000000
121592 0.72 738.000000
121593 0.72 738.000000
121594 0.72 738.000000
121595 0.72 738.000000
121596 0.72 738.000000
121597 0.72 738.000000
121598 0.72 738.000000
121599 0.72 738.000000
121600 0.72 738.000000
我想把每列的整行都放到列表中。
例如,有一个列表result_temp = []
for i in range(0, lenghofColumn):
result_temp.append(result[:,i])
但是,它给了我一个错误,说Error: TypeError: unhashable type
File "public/make_bokeh.py", line 49, in <module>
real_result.append(result_temp[:,i])
有没有什么办法
请帮帮我
提前谢谢
其他几个选择
Alt 1
在
list
上下文中使用df
时,您将得到每个列名Alt 2
玩得开心
map
Alt 3
zip
与tuple
的转座与
list
s备选方案4
最好是转置值,转换为
numpy array
,最后转换为list
:我认为您可以使用
list comprehension
where按列名称循环,并按[]
按名称选择每个列,然后转换为list
:同:
如果要使用您的代码,则需要^{} 按位置选择列:
同:
相关问题 更多 >
编程相关推荐