多数据问卷标称值如何调整

2024-10-04 09:17:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有时隙数据。你知道吗

ds = [ds01, ds02, ds03, ds04, ...]

对于循环中的结果,使用:

nhelp = []
for d in ds:
    nhelp.append(d.groupby(list(d)[1]).size().sum)  #single column
nhelp

例如,最喜欢的颜色(哪些数据表示为1 2 3。。。(在问卷中) 我得到了:

[<bound method Series.sum of color
1.0    215
2.0    202
3.0    215
4.0    178
dtype: int64>, <bound method Series.sum of color
1.0    252
2.0    244
3.0    241
4.0    133
dtype: int64>, <bound method Series.sum of color
........ 
dtype: int64>]

现在我要总结所有时间段的颜色,并在一个图表中显示结果。(这里我尝试了pivot、crosstable、loops、-将list转换为array或/和dataframe-sumation和plot失败,也不可能迭代这个变量,但我可以访问值,例如nhelp[1][1])


Tags: of数据颜色dsmethodlistcolorseries
1条回答
网友
1楼 · 发布于 2024-10-04 09:17:50

我认为您需要通过^{}联接所有数据,然后通过Index求和:

nhelp = []
for d in ds:
    nhelp.append(d.groupby(list(d)[1]).size())

out = pd.concat(nhelp).sum(level=0)

或列表理解:

nhelp = [d.groupby(list(d)[1]).size() for d in ds]
out = pd.concat(nhelp).sum(level=0)

相关问题 更多 >