pandas 增加一行数据

import pandas as pd
df = pd.DataFrame(columns=('lib', 'qty1', 'qty2'))
>>> for i in range(5):
>>>     df.loc[i] = [randint(-1,1) for n in range(3)]
>>>
>>> print(df)

    lib  qty1  qty2
0    0     0    -1
1   -1    -1     1
2    1    -1     1
3    0     0     0
4    1    -1    -1

[5 rows x 3 columns]

备注:列增加的话,可以使用:

df['lib2']=[2,3,4,2,2]

你可能感兴趣的:(机器学习,python学习)