如何在DataFrame 中优雅的增加一行,一列
<font color=‘darkgreen’,size=4.5> 优雅的增加一行,一定要优雅!
df=DataFrame(np.arange(16).reshape((4,4)),index=['a','b','c','d'],columns=['one','two','three','four'])
df.loc['new_raw'] = '3'
df
Out[84]:
one two three four
a 0 1 2 3
b 4 5 6 7
c 8 9 10 11
d 12 13 14 15
new_raw 3 3 3 3
<font color=‘green’,size=4.5> 优雅的增加一列,一定要优雅!
df['new_colu']='12'#向 DataFrame 添加一列,该列为同一值
df
Out[93]:
one two three four new_colu
a 0 1 2 3 12
b 4 5 6 7 12
c 8 9 10 11 12
d 12 13 14 15 12
new_raw 3 3 3 3 12