我有一个带有数据的 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/