添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
听话的猴子  ·  java.sql.sqlexception ...·  2 年前    · 
笑点低的人字拖  ·  UITextView_wx6103b5205 ...·  2 年前    · 

TypeError: append() 缺少1个必要的位置参数: 'other' 。

9 人关注

我有几个数据框(形状相同),我想附加创建一个更大的数据框。 每个数据框的类型都是一样的。

C-Mastersheet.xlsx   <class 'pandas.core.frame.DataFrame'>
D-Mastersheet.xlsx   <class 'pandas.core.frame.DataFrame'>
L-Mastersheet.xlsx   <class 'pandas.core.frame.DataFrame'>

并且看起来像。

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

       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

   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

我正试图返回输出。

  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

我试图用下面的代码来做这件事,它在一个目录周围循环。

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)

然而,我得到了以下类型的错误。

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

我以前没有遇到过这种情况。

5 个评论
shouldn't this be ConsolidatedData = pd.DataFrame() ?
是的,这将是它....
也许应该删除这个问题,因为它是一个错字
jpp
@EdChum, 或者(我们不要把这个解释放在一边),在类和类实例之间有一个根本性的误解!
cs95
@jpp Sure, but this is 这是一个由于打错字而造成的错误,不可能对未来的访客有帮助。我将保留你的答案,但也保留VTC。
python
pandas
Stacey
Stacey
发布于 2019-01-09
1 个回答
jpp
jpp
发布于 2019-01-09
已采纳
0 人赞同

This is the problem:

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

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

你需要的是。

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