【问题标题】:Append only last row in a panda dataframe to a new dataframe [duplicate]仅将熊猫数据框中的最后一行附加到新数据框[重复]
【发布时间】:2021-04-27 21:22:22
【问题描述】:

我有以下熊猫数据框:(df)

如何仅将最后一行(日期 2021-01-22)附加到新数据帧 (df_new)?

【问题讨论】:

标签: python pandas dataframe append


【解决方案1】:
df_new = df_new.append(df.tail(1)) 

如果 df_new 没有定义。下面的代码就可以了。

df_new = df.tail(1)

【讨论】:

  • 我得到以下 NameError: name 'df_new' is not defined。如何定义 df_new? df_new = pd.DataFrame(last_row) ,对吗?
  • df_new = df.tail(1) 可以解决问题。
猜你喜欢
  • 2021-09-24
  • 2019-10-22
  • 2020-08-01
  • 2019-01-14
  • 2018-09-29
  • 1970-01-01
  • 2018-02-08
  • 2017-06-13
  • 2014-01-03
相关资源
最近更新 更多