在将excel文档读取到数据框期间,我收到此警告:
*
Warning (from warnings module):
File "C:\Users\Slobo\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\frame.py", line 6211
sort=sort)
FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.
To accept the future behavior, pass 'sort=False'.
To retain the current behavior and silence the warning, pass 'sort=True'.
*
要从特定文件夹中读取所有文档,请使用以下方法:
`for f in glob.glob(dirname + "/*.xlsx")`:
#where dirname is the path to the folder, and then for reading documents:
pd.read_excel(f)
我要打印在读取数据框时会引起警告出现的文档名称。
该怎么做?
答案 0 :(得分:1)
import warnings
warnings.filterwarnings("error")
for f in glob.glob(dirname + "/*.xlsx"):
try:
pd.read_excel(f)
except Warning as w:
print(f)