从数据框的开头向 pandas 数据框的末尾添加值数据、末尾、开头、pandas

2023-09-07 02:23:19 作者:谁念西风独自凉

I have a pandas data frame that looks something like this:

  A B C
0 1 2 3
1 4 5 6
2 7 8 9

And I would like to add row 0 to the end of the data frame and to get a new data frame that looks like this:

  A B C
0 1 2 3
1 4 5 6
2 7 8 9
3 1 2 3
从零开始学Python pandas 数据框部分03

What can I do in pandas to do this?

解决方案

You can try:

df = df.append(df.iloc[0], ignore_index=True)