for循环将Series作为新行插入DataFrame
导入包
from pandas import DataFrame
import pandas as pd
import numpy as np
创建df
df = DataFrame(np.random.randn(4, 5), columns=['A', 'B', 'C', 'D', 'E'])
print(df)
输出:
创建Series
这里要指定与df中相同的索引名字
s1 = pd.Series([1,2,3,4,5])
s1.index = ['A','B','C','D','E']
print(s1)
将Series插入df
df = df.append(s1,ignore_index=True)
print(df)
通过for循环插入新行
for i in range(0,4):
s = pd.Series([i,888,999,100,200])
s.index = ['A','B','C','D','E']
df = df.append(s, ignore_index=True)
print(df)