1

I have a function which will give me a dataframe olddataframe as output in a loop, i want to combine them into a single Dataframe as newdataframe by appending and i tried the below code

newdataframe=pd.DataFrame
newdataframe.append(olddataframe,ignore_index=False)

it throws an error like below

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

what needs to be done to fix this

foret
  • 337
  • 1
  • 5
  • 14

2 Answers2

3

Use newdataframe=pd.DataFrame() in the first line instead.

By using newdataframe=pd.DataFrame you didn't create a data frame, rather created a new name for DataFrame, so what you wrote was pd.DataFrame.append(olddataframe,ignore_index=False), and your error is because the append function need 2 DataFrames, rather than 1.

Shir
  • 1,157
  • 13
  • 35
3

I suggest create list of DataFrames and then concat only once, if performance is important:

dfs = []
for olddataframe in data:
    #data processing 
    dfs.append(olddataframe)

newdataframe = pd.concat(dfs, ignore_index=False)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252