TypeError:append()缺少1个必需的位置参数:“ other”

Sta*_*cey 5 python pandas

我想追加几个(相同形状的)数据框,以创建一个更大的数据框。Tee单个数据帧都具有以下类型:

C-Mastersheet.xlsx   <class 'pandas.core.frame.DataFrame'>
D-Mastersheet.xlsx   <class 'pandas.core.frame.DataFrame'>
L-Mastersheet.xlsx   <class 'pandas.core.frame.DataFrame'>
Run Code Online (Sandbox Code Playgroud)

看起来像:

C-Mastersheet.xlsx

   First Name  Last name        Dept  Location  Status      Concat 
0          Jo      Jones    Accounts   Bristol Current     JonesJo
1         Sid      Smith       Sales      Hull     New    SmithSid
Run Code Online (Sandbox Code Playgroud)

D-Mastersheet.xlsx

       First Name  Last name        Dept  Location  Status      Concat 
0            Phil      Evans  Production      Hull Current   EvansPhil
1           Sarah      Heath   Marketing   Bristol Current  HeathSarah
2            Jane       Hill    Accounts   Bristol Current    HillJane
3             Amy     Cooper       Sales      Hull Current   CooperAmy
Run Code Online (Sandbox Code Playgroud)

L-Mastersheet.xlsx

   First Name  Last name        Dept  Location  Status      Concat
0      Marcus      Price  Operations      Hull Current PriceMarcus
1      Andrew       King      Design   Bristol Current  KingAndrew
2        Emma       Lane   Marketing   Bristol Current    LaneEmma
3       Brian       Deen    Accounts   Bristol Current   DeenBrian       
4       Steve      Jacks      Design   Bristol Current  JacksSteve
Run Code Online (Sandbox Code Playgroud)

我试图返回输出:

  First Name  Last name        Dept  Location   Status      Concat 
 0         Jo      Jones    Accounts   Bristol Current     JonesJo
 1        Sid      Smith       Sales      Hull New        SmithSid
 2       Phil      Evans  Production      Hull Current   EvansPhil
 3      Sarah      Heath   Marketing   Bristol Current  HeathSarah
 4       Jane       Hill    Accounts   Bristol Current    HillJane
 5        Amy     Cooper       Sales      Hull Current   CooperAmy
 6     Marcus      Price  Operations      Hull Current PriceMarcus
 7     Andrew       King      Design   Bristol Current  KingAndrew
 8       Emma       Lane   Marketing   Bristol Current    LaneEmma
 9      Brian       Deen    Accounts   Bristol Current   DeenBrian       
10      Steve      Jacks      Design   Bristol Current  JacksSteve
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下代码循环绕目录执行此操作:

ConsolidatedData = pd.DataFrame

for i in os.listdir(os.chdir(returnsfolder)):
    if i.endswith(".xlsx"):
        )
        rawFilePath = returnsfolder +'\\'+ i

        DeptReturn = openRawDeptReturn(rawFilePath)

        ConsolidatedData = ConsolidatedData.append(DeptReturn,ignore_index=True)
Run Code Online (Sandbox Code Playgroud)

但是,我得到以下类型错误:

TypeError: append() missing 1 required positional argument: 'other'
Run Code Online (Sandbox Code Playgroud)

我以前没有遇到过。可以请一些建议吗

谢谢

jpp*_*jpp 11

这就是问题:

df = pd.DataFrame           # returns class
df = df.append(DeptReturn)  # TypeError: append() missing 1 required positional argument: 'other'
Run Code Online (Sandbox Code Playgroud)

错误背后的原因是方法的第一个参数是类实例。在这种情况下,推断类实例为DeptReturn并且没有'other'提供任何参数。

您需要的是:

df = pd.DataFrame()         # returns class instance
df = df.append(DeptReturn)  # returns instance with method applied
Run Code Online (Sandbox Code Playgroud)

对于第一个参数,我们具有类instance df,因为该方法将应用于该实例。第二个参数是DeptReturn

另请参阅:自我的目的是什么?