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

标签 python pandas time-series

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

相关文章:

python - NumPy - 麻烦向量化方法

Python 的 next() 函数

python - Pandas .DataFrame : mappings a column of a list of keys to a column of the list of values

python - 加载 pb 文件 : DecodeError: Error parsing message

python - 通过 jenkins-plugin 运行 pip?

python - 使用 Python 从具有空白字段的文件中删除行

python - 如何在 Pandas 系列中用 at[] 替换 set_value

r - R中10分钟频率的时间序列

r - 将 %B.%Y 转换为 R 中的日期返回 NA

time-series - 如何查询按设备对齐的数据值,并使用 Apache IoTDB 删除一定数量的设备结果?