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 3, 3, 3, 1, 3, 3, 1, 2, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, 1, 2, 3, 3, 1, 3, 2, 3, 3, 3, 2, 3, 3, 1, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3]]}
有人提供了以下代码,它遍历键和值列表,并计算1,2和3的频率。为了在绘制这些数据时让我的生活更轻松,我想把它放在一个数据框中,所以,按照我在这篇文章中找到的例子,“Getting List of List to Pandas Data Frame”我使用了以下代码:
from pandas import DataFrame
keys=[]
values=[]
for key, value in data.iteritems():
keys.append(key)
one = 0
two = 0
three = 0
for x in value[0]:
if x == 1:
one+=1
elif x == 2:
two+=1
elif x == 3:
three+=1
values.append([one,two,three])
print keys
print values
理想情况下,我的数据框将'hat1'
到'hat21'
作为列(按照正确的顺序排列),并且在行中它将包含1个,2个和3个相应的计数'帽子'。例如(忽略数字),如果只有三个帽子,下面是我想象的。
'hat1' 'hat2' 'hat3'
1 27 10 56
2 4 6 254
3 1 1 1
然而,当我使用代码df = DataFrame(values)
时,数据框似乎是转置的,我不太清楚如何获取相应的标题,因为当我尝试使用键作为我的标题时,我得到了一个错误说AssertionError: 21 columns passed, passed data had 3 columns
0 1 2
0 27 10 56
1 4 6 254
2 1 1 1
3 3 480 1
4 252 1 1
5 6 17 10
6 3 2 142
7 6 211 3
8 313 5 12
9 1 193 5
10 243 20 22
11 58 31 93
12 5 190 65
13 80 81 120
14 122 54 18
15 156 154 17
16 76 76 88
17 10 55 8
18 280 26 62
19 19 42 21
20 54 82 310
感谢您的帮助。
答案 0 :(得分:2)
您可以使用转置和计数轻松实现您想要的效果,例如:
import pandas as pd
# use .transpose or .T can transpose your dataframe
df = pd.DataFrame(data).T
# then I simply use list comprehension and count element 1,2,3 in it
# and assign to new column, that's it
df[1] = [d.count(1) for d in df[0]]
df[2] = [d.count(2) for d in df[0]]
df[3] = [d.count(3) for d in df[0]]
结果:
df.head(10)
0 1 2 3
hat1 [1, 2, 3] 1 1 1
hat10 [1, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 2, 3, ... 243 20 22
hat11 [1, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ... 1 193 5
hat12 [1, 2, 3, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, ... 5 190 65
hat13 [1, 2, 3, 2, 1, 2, 1, 3, 2, 1, 1, 2, 1, 1, 2, ... 58 31 93
hat14 [1, 2, 3, 1, 2, 1, 2, 3, 1, 1, 1, 3, 3, 1, 2, ... 122 54 18
hat15 [1, 2, 3, 1, 1, 2, 3, 3, 2, 3, 3, 3, 3, 2, 3, ... 80 81 120
hat16 [1, 2, 3, 1, 1, 1, 1, 2, 3, 1, 2, 2, 2, 2, 2, ... 76 76 88
hat17 [1, 2, 3, 1, 1, 1, 3, 2, 2, 1, 2, 2, 2, 1, 2, ... 156 154 17
hat18 [1, 2, 3, 1, 1, 1, 1, 3, 1, 1, 1, 3, 1, 1, 1, ... 280 26 62
最后转置回来并为替换列分配数据框:
df = df[[1,2,3]].T
print df
hat1 hat10 hat11 hat12 hat13 hat14 hat15 hat16 hat17 hat18 ... 1 1 243 1 5 58 122 80 76 156 280 ...
2 1 20 193 190 31 54 81 76 154 26 ...
3 1 22 5 65 93 18 120 88 17 62 ...
hat2 hat20 hat21 hat3 hat4 hat5 hat6 hat7 hat8 hat9
1 252 10 54 3 3 6 313 6 4 27
2 1 55 82 480 2 17 5 211 6 10
3 1 8 310 1 142 10 12 3 254 56