FutureWarning: Sorting because non-concatenation axis is not aligned. A future version of pandas will change to not sort by default.
问题描述:在对表格进行操作时,出现了上面这个FutureWarning
,同时出现了表格的标题被打乱了顺序。解决办法如下:
import pandas as pd
import os
path = r'E:\在线文档'
file_list = []
for root, dirs, files in os.walk(path):
for name in files:
file_list.append(os.path.join(root, name))
temp = pd.DataFrame()
for i in file_list:
print(i)
df = pd.read_excel(i,sheet_name=1,skiprows=2)
df = df.loc[ :, ~df.columns.str.contains("^Unnamed")]
df['日期'].fillna(method='ffill', inplace=True)
df['省份'].fillna(method='ffill', inplace=True)
df['地区/单位'].fillna(method='ffill', inplace=True)
temp = pd.concat([temp,df])
temp
- 解决办法是第15行的代码, 把所有
unnamed
的列给去掉,再处理,就可以。 这是在试验了好几个方法之后才最终成功的方法,特此记录一下。