loc()
df_test = pd.DataFrame([['Snow','M',22],['Tyrion','M',32],['Sansa','F',18],['Arya','F',14]], columns=['name','gender','age'])
df_test
df_test.loc[4] = ['tom','M',9]
df_test.loc[5] = {'name':'jerry'}
df_test
append()
import warnings
warnings.filterwarnings('ignore')
df_test = pd.DataFrame([['Snow','M',22],['Tyrion','M',32],['Sansa','F',18],['Arya','F',14]], columns=['name','gender','age'])
df_test
temp_df = pd.DataFrame()
test_list = [2,3]
for x in test_list:
for index,row in df_test.iterrows():
if x==index:
temp_df = temp_df.append(row)
temp_df
temp_df = pd.DataFrame()
test_list = [2,3]
for x in test_list:
for index,row in df_test.iterrows():
if x==index:
temp_df = temp_df.append(pd.DataFrame(row).T)
temp_df
concat() (*重要)
pd.concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
keys=None, levels=None, names=None, verify_integrity=False,
copy=True)
接上
df_test2 = pd.DataFrame([['Snow','M',22],['Tyrion','M',32],['Sansa','F',18],['Arya','F',14]], columns=['name','gender','age'])
df_test2
frames = [df_test,df_test2]
result = pd.concat(frames,ignore_index = True)
result