0

I am running into this warning in my Jupyter notebook and I am relatively new to python and coding in general. Any help would be appreciated :)

Warning/Error:

FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.

Code causing the error:


dataCollection = pd.DataFrame()
for file in list_of_files:
    procData = pd.read_table(file, header=None, sep='\s+')
    procData.columns = columns
    procData['subject_id'] = int(file[-5])
    dataCollection = dataCollection.append(procData, ignore_index=True)

dataCollection.reset_index(drop=True, inplace=True)
dataCollection.head()

The output I am expecting would be a dataframe table with column headings.

buran
  • 13,682
  • 10
  • 36
  • 61
Sou
  • 3
  • 1

1 Answers1

0

The error is telling you to use pandas.concat in place of frame.append.

dataCollection = pd.DataFrame()
for file in list_of_files:
    procData = pd.read_table(file, header=None, sep='\s+')
    procData.columns = columns
    procData['subject_id'] = int(file[-5])
    dataCollection = pd.concat([dataCollection, procData], ignore_index=True)

Of course, this is an inefficient way of concatenating an arbitrary set of frames. Get all the frames in a list, then call concat once.

frames = []
for f in list_of_files:
    procData = pd.read_table(f, header=None, sep='\s+')
    procData.columns = columns
    procData['subject_id'] = int(file[-5])
    frames.append(procData)

dataCollection = pd.concat(frames, ignore_index=rue)
chepner
  • 497,756
  • 71
  • 530
  • 681