简体   繁体   English

类型错误:append() 缺少 1 个必需的位置参数:“其他”

[英]TypeError: append() missing 1 required positional argument: 'other'

I have several dataframes (of the same shape) that I want to append creating one larger data-frame.我有几个数据框(形状相同),我想附加这些数据框以创建一个更大的数据框。 Tee individual data-frames all have the type: 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'>

and look like:看起来像:

C-Mastersheet.xlsx 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

D-Mastersheet.xlsx 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

L-Mastersheet.xlsx 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

I am trying to return the output:我正在尝试返回输出:

  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

I am trying to do this using the follwing code whioch loops around a directory:我正在尝试使用以下围绕目录循环的代码来执行此操作:

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)

I am however getting the following type error:但是,我收到以下类型错误:

TypeError: append() missing 1 required positional argument: 'other'

I have not come across this before.我以前没有遇到过这种情况。

This is the problem:这就是问题:

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

The reason behind the error is the first argument of a method is the class instance.错误背后的原因是方法的第一个参数是类实例。 In this case, the class instance is inferred to be DeptReturn and there is no 'other' argument supplied.在这种情况下,类实例被推断为DeptReturn并且没有提供'other'参数。

What you need is:你需要的是:

df = pd.DataFrame()         # returns class instance
df = df.append(DeptReturn)  # returns instance with method applied

For the first argument we have the class instance df , since the method is being applied on that instance.对于第一个参数,我们有类实例df ,因为该方法正在该实例上应用。 The second argument is DeptReturn .第二个参数是DeptReturn

See also: What is the purpose of self?另见: 自我的目的是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:corr()缺少1个必需的位置参数:“ other” - TypeError: corr() missing 1 required positional argument: 'other' 类型错误:Iniciar() 缺少 1 个必需的位置参数:“数据”并且 append 失败 - TypeError: Iniciar() missing 1 required positional argument: 'data' and failed append Pygame-TypeError:缺少1个必需的位置参数 - Pygame - TypeError: Missing 1 required positional argument 类型错误:exe() 缺少 1 个必需的位置参数:&#39;self&#39; - TypeError: exe() missing 1 required positional argument: 'self' 类型错误:<lambda> () 缺少 1 个必需的位置参数 - TypeError: <lambda>() missing 1 required positional argument 类型错误:forward() 缺少 1 个必需的位置参数:&#39;negative&#39; - TypeError: forward() missing 1 required positional argument: 'negative' TypeError:SetStrength()缺少1个必需的位置参数:“ strength” - TypeError: SetStrength() missing 1 required positional argument: 'strength' TypeError:str()缺少1个必需的位置参数:&#39;self&#39; - TypeError: str() missing 1 required positional argument: 'self' TypeError:generator()缺少1个必需的位置参数:“ json” - TypeError: generator() missing 1 required positional argument: 'json' TypeError: main() missing 1 required positional argument: 'self' - TypeError: main() missing 1 required positional argument: 'self'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM