在熊猫上添加新行?

时间:2014-12-14 04:15:30

标签: python pandas

为什么我无法在pandas上添加新行?

data="""lname    fname   rno_cd    eri_cd
0    CRUISE   TOM     E         1
1    DEPP     JOHNNY  Y         0
2    DICAPR   LENARDO Nan       1
3    PITT     BRAD    Nan       1
4    MOST     JEFF    A         0
5    HANKS    TOM     Nan       1
6    BRANDO   MARLON  C         1
7    WILLIAMS ROBIN   F         1
8    DOWNEY   ROBERT  B         1
9    PACINO   AL      E         1"""

import pandas as pd
from io import StringIO

df= pd.read_csv(StringIO(data.decode('UTF-8')),delim_whitespace=True )


df.loc[-1]= ['2','3','4','4']

每当我尝试执行代码时,我都会收到错误消息。

我也试过了:

df.loc[len(df)+1]

1 个答案:

答案 0 :(得分:1)

尝试.iloc属性:

df.iloc[-1] = []

更多here