我在我的Jupyter笔记本上遇到了这个警告,我对python和编程相对陌生。任何帮助都将是感激的:)
警告/错误:
FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
导致错误的代码:
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()
我期望的输出将是一个带有列标题的数据帧表。
错误提示您使用pandas.concat
代替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)
当然,这是一种连接任意帧集的低效方式。获取所有帧在一个列表中,然后调用concat
一次。
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)