gpt4 book ai didi

python - 从 pandas.core.series.Series 中删除前导零

转载 作者:太空宇宙 更新时间:2023-11-03 12:36:40 27 4
gpt4 key购买 nike

我有一个带有数据的 pandas.core.series.Series

0    [00115840, 00110005, 001000033, 00116000...
1 [00267285, 00263627, 00267010, 0026513...
2 [00335595, 00350750]

我想从系列中删除前导零。我试过了

x.astype('int64')

但是得到了错误信息

ValueError: setting an array element with a sequence.

你能建议我如何在 python 3.x 中执行此操作吗?

最佳答案

s=pd.Series(s.apply(pd.Series).astype(int).values.tolist())
s
Out[282]:
0 [1, 2]
1 [3, 4]
dtype: object

数据输入

s=pd.Series([['001','002'],['003','004']])

更新:感谢 Jez 和冷点:-)

pd.Series(s.apply(pd.Series).stack().astype(int).groupby(level=0).apply(list))
Out[317]:
0 [115840, 110005, 1000033, 116000]
1 [267285, 263627, 267010, 26513]
2 [335595, 350750]
dtype: object

关于python - 从 pandas.core.series.Series 中删除前导零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48139274/

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