python在数组中添加一行数据的方法:
1、直接插入一行:import pandas as pd
from pandas import DataFrame
df3=DataFrame(np.arange(16).reshape((4,4)),index=['a','b','c','d'],columns=['one','two','three','four'])
# 新插入的行一定要加 index,不然会报错
df3.loc['new'] = ['a','a','a','a']
# 运行结果为
onetwothreefour
a0123
b4567
c891011
d12131415
newaaaa
2、新建一个同样的 dataframe, 然后合并两个dataframedf4 = pd.DataFrame([6,6,6,6]).T
# 修改df4的column和df3的一致
df4.columns = df3.columns
# 把两个dataframe合并,需要设置 ignore_index=True
df_new = pd.concat([df3,df4],ignore_index=True)
# 运行结果
onetwothreefour
00123
14567
2891011
312131415
4aaaa
56666
更多Python知识请关注Python自学网。