pandasのdataframeに行を追加する方法
df = pd.concat([df,df1])
例
dfにdf1,df2,df3を結合した結果を代入している例
import pandas as pd
import numpy as np
# 結合用のdataframe作成
df1 = pd.DataFrame([[25,'pika',88,'Electric',np.NaN,np.NaN],
[131,'rara',80,'Water','Ice',np.NaN]])
# 結合用のdataframe作成
df2 = pd.DataFrame([[143,'gon',82,'Normal',np.NaN,np.NaN]])
# 結合用のdataframe作成
df3 = pd.DataFrame([[3,'fushi',84,'Grass','Poison',np.NaN],
[6,'kage',84,'Fire','Flying',np.NaN],
[9,'kame',84,'Water',np.NaN,np.NaN]])
df = pd.concat([df1,df2,df3])
# 結果確認
print(df)
"""
0 1 2 3 4 5
0 25 pika 88 Electric NaN NaN
1 131 rara 80 Water Ice NaN
0 143 gon 82 Normal NaN NaN
0 3 fushi 84 Grass Poison NaN
1 6 kage 84 Fire Flying NaN
2 9 kame 84 Water NaN NaN
"""
コメント