[英]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.