如何用一行和三列创建一个图,在每个列中我绘制一个直方图?数据来自于这个DataFrame:
import pandas as pd
import matplotlib as plt
d = {'col1': ['A','A','A','A','A','A','B','B','B','B','B','B','C','C','C','C&
对于一个可迭代的对象,我们可以使用 for item in items: 但是,如果我有两个并排的可迭代程序,比如有两列的pandas数据帧,会怎么样呢?我可以使用上面的方法遍历一列,但是有没有一种更优雅的方法同时遍历两列呢? import pandas as pd
df = pd.DataFrame({'col 1': [1,2,3,4,5], 'col 2': [6,7,8,9,10]})
i = 0
for j in df['col 1']:
print(j)
print(df['col 2'][i])
我有9,000列和100行的数据。我想在每3列之后插入一列,使其值等于所有行的50。
现有DataFrame
0 1 2 3 4 5 6 7 8 9....9000
0 a b c d e f g h i j ....x
1 k l m n o p q r s t ....x
.
.
100 u v w x y z aa bb .x
理想的DataFrame
0 1 2 3 4 5 6 7 8 9....12000
0 a b c 50 d e f 50 g h i j ....x
1 k l m 50 n o p 50 q r s t ....x
.
.
100 u v w 50