如何附加到包含时间序列的 DataFrame 中的列

Posted

技术标签:

【中文标题】如何附加到包含时间序列的 DataFrame 中的列【英文标题】:How to append to a column in a DataFrame containing time sequences 【发布时间】:2018-12-19 19:46:18 【问题描述】:

如何将另一个列表附加到存储在 timeseq=[xyz,xyz...,xyz] 中的 df_final['time_seq'] 列

【问题讨论】:

您将需要生成完整的新行,可能带有默认值。 【参考方案1】:

针对您的特定问题:

additional_time_seq = [1234567, 1234568]
# i the index of the row you want
# the line below gives you the time_seq list
time_seq_to_append = df_final.loc[df_final.index[i], 'time_seq']
# the line below extends the time_seq list with the additional_time_seq
time_seq_to_append.extend(additional_time_seq)

一般情况下,df.loc[df.index[i], 'NAME']gives you the element for a named column with integer indices,因为在您的情况下这是一个列表,您可以使用 Python 列表的内置 extends 方法。

【讨论】:

以上是关于如何附加到包含时间序列的 DataFrame 中的列的主要内容,如果未能解决你的问题,请参考以下文章

将行附加到 pandas DataFrame 而不制作新副本

将多个 DataFrame 附加到多个现有的 Excel 工作表

从for循环将系列附加到dict或list或dataframe?

Python Pandas Dataframe:如何同时将多个索引附加到列表中?

如何将 Python 字典附加到 Pandas DataFrame,将键与列名匹配

是否有更快的方法来获取基于线性回归模型的值并将其附加到 DataFrame 中的新列?