gpt4 book ai didi

python - Pandas:concat 函数删除数据帧的先前排序

转载 作者:行者123 更新时间:2023-12-04 07:25:09 24 4
gpt4 key购买 nike

考虑两个名为“socio_demo”([198 行 x 15 列])和 UPDRS_sorted([198 行 x 70 列])的数据帧。
让我们做:

socio_demo_sorted = socio_demo.sort_values(['NUMERO_CENTRE_1','NUMERO_INCLUSION_1'])
UPDRS_sorted = UPDRS.sort_values(['NUMERO_CENTRE_2','NUMERO_INCLUSION_2'])
UPDRS_sorted['NUMERO_CENTRE_2'] 给出
Out[22]: 
3 1
9 1
13 1
18 1
24 1
..
6 6
16 6
20 6
25 6
34 6
Name: NUMERO_CENTRE_2, Length: 198, dtype: int64
现在让我们连接两个排序的数据集:
frames = [socio_demo_sorted,UPDRS_sorted]
full_data = pd.concat(frames,axis = 1)
这给出了预期的 [198 行 x 85 列] 形状。
然而,做
full_data['NUMERO_CENTRE_2']
返回原始(未排序)UPDRS 数据:
0      3
1 4
2 2
3 1
4 5
..
193 1
194 1
195 1
196 1
197 1
Name: NUMERO_CENTRE_2, Length: 198, dtype: int64
我不明白为什么“.sort_values”函数的效果在这里丢失了。

最佳答案

在您的情况下 concatignore_index

out = pd.concat(frames,ignore_index=True)

关于python - Pandas:concat 函数删除数据帧的先前排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68245579/

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