# Append Row to DataFrame
list_row = ["Hyperion", 27000, "60days", 2000]
df.loc[len(df)] = list_row
# Insert Dict to the dataframe using DataFrame.append()
new_row = {'Courses':'Hyperion', 'Fee':24000, 'Duration':'55days', 'Discount':1800}
df2 = df.append(new_row, ignore_index=True)
# Append new row to specifig index name
df2 = df.append(pd.DataFrame([new_row],index=['7'],columns=df.columns))
# Append row to the DataFrame
df2 = df.append(pd.Series(new_row, index=df.columns, name='7'))
# Using pandas.concat() to append a row
new_row = pd.DataFrame({'Courses':'Hyperion', 'Fee':24000, 'Duration':'55days', 'Discount':1800}, index=[0])
df2 = pd.concat([new_row,df.loc[:]]).reset_index(drop=True)
# Append specific row/index name using DataFrame.loc[]
df.loc['7', :] = ['Hive',25000,'45days',2000]
# Append row in DataFrame using DataFrame.loc[]
df.loc['7'] = ['Hive',25000,'45days',2000]
반응형
'Python' 카테고리의 다른 글
[ Pandas ] Dataframe 필요한 열(column) 추출 (0) | 2023.05.07 |
---|---|
[Python] 딕셔너리 key값으로 value값 찾기, value값으로 key값 찾기 (0) | 2022.12.12 |