Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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:
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
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
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.
–
–
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.
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. The second argument is DeptReturn
.
See also: What is the purpose of self?
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.