gpt4 book ai didi

python - 将列表列表转换为数据框

转载 作者:行者123 更新时间:2023-12-01 04:52:14 26 4
gpt4 key购买 nike

两天前,我在计算多个“帽子”中 1、2 和 3 的频率时遇到了一些问题,得到了一些帮助。

data = {'hat9': [[1, 2, 3, 2, 2, 3, 3, 3, 1, 1, 1, 3, 1, 3, 1, 3, 3, 2, 2, 3, 3, 2, 3, 2, 1, 1, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 3, 1, 3, 3, 3, 3, 1, 2, 1, 1, 3, 3, 1, 3, 1, 2, 1, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 1, 3, 1, 3, 3, 1, 3, 3, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 3]], 'hat8': [[1, 2, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 2, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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 3, 2, 3, 1, 3, 3, 3, 2, 3, 2, 1, 3, 2, 3, 1, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 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) 时,数据帧似乎已转置,并且我不太知道如何获取适当的 header ,因为当我尝试使用键作为我的标题,我收到一条错误消息 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

感谢您的帮助。

最佳答案

您可以使用转置计数轻松实现您想要的目标,如下所示:

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

关于python - 将列表列表转换为数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28180301/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com