gpt4 book ai didi

python - 展平 pandas 数据框列

转载 作者:行者123 更新时间:2023-11-30 22:45:28 25 4
gpt4 key购买 nike

我目前有以下列:

0          [Joe]
1 John
2 Mary
3 [Joey]
4 Harry
5 [Susan]
6 Kevin

我似乎无法在不使用 [] = NaN 制作行的情况下删除 []

需要明确的是,我希望该列看起来像这样:

0            Joe
1 John
2 Mary
3 Joey
4 Harry
5 Susan
6 Kevin

有人可以帮忙吗?

最佳答案

您的标题似乎暗示您的系列中的某些元素是列表。

设置

s = pd.Series([['Joe'], 'John', 'Mary', ['Joey'], 'Harry', ['Susan'], 'Kevin'])
s

0 [Joe]
1 John
2 Mary
3 [Joey]
4 Harry
5 [Susan]
6 Kevin
dtype: object

选项 1
适用于pd.Series

s.apply(pd.Series).squeeze()

0 Joe
1 John
2 Mary
3 Joey
4 Harry
5 Susan
6 Kevin
Name: 0, dtype: object

关于python - 展平 pandas 数据框列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41196059/

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