将项目添加到pandas.Series?

将项目添加到pandas.Series?,第1张

项目添加到pandas.Series?

附加项目转换为

Series

>>> ds = pd.Series([1,2,3,4,5]) >>> ds.append(pd.Series([6]))0    11    22    33    44    50    6dtype: int64

或使用

Dataframe

>>> df = pd.Dataframe(ds)>>> df.append([6], ignore_index=True)   00  11  22  33  44  55  6

最后一种选择,如果您的索引没有差距,

>>> ds.set_value(max(ds.index) + 1,  6)0    11    22    33    44    55    6dtype: int64

您可以将numpy作为最后的手段:

>>> import numpy as np>>> pd.Series(np.concatenate((ds.values, [6])))


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5655387.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存