Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何打印在读取数据框时显示警告的文档名称_Python_Pandas_Warnings - Fatal编程技术网

Python 如何打印在读取数据框时显示警告的文档名称

Python 如何打印在读取数据框时显示警告的文档名称,python,pandas,warnings,Python,Pandas,Warnings,在将excel文档读取到数据框的过程中出现以下警告: * * 要读取特定文件夹中的所有文档,我使用以下方法: `for f in glob.glob(dirname + "/*.xlsx")`: #where dirname is the path to the folder, and then for reading documents: pd.read_excel(f) 我想打印文档的名称,该文档在读取数据框时会出现警告 如何做到这一点?这对我不起作用,我不知道为什么…唯一

在将excel文档读取到数据框的过程中出现以下警告:

*

*

要读取特定文件夹中的所有文档,我使用以下方法:

`for f in glob.glob(dirname + "/*.xlsx")`:
    #where dirname is the path to the folder, and then for reading documents:
    pd.read_excel(f)
我想打印文档的名称,该文档在读取数据框时会出现警告


如何做到这一点?

这对我不起作用,我不知道为什么…唯一的区别是我有df=pd.read\u excelf.-没有错误,只是再次显示警告,而不打印文档名称。请您现在检查一下好吗?现在显示回溯最近的调用:文件C:\Users\Slobo\Desktop\Python\Project\Export\import.py,第63行,在df=df.appenddf中,忽略_index=True。。。因为我将所有文档附加到一个数据帧中,之后显示相同的警告,但由于错误而中断脚本执行。我成功了…我将:import warnings warnings.filterwarningerror for f放入glob.globdirname+/.xlsx:try:df=pd.read_excelf df=df.appenddf,忽略_index=True,警告为w:printf除外*
import warnings
warnings.filterwarnings("error")

for f in glob.glob(dirname + "/*.xlsx"):
    try:
       pd.read_excel(f)
    except Warning as w:
        print(f)
import warnings
warnings.filterwarnings("error")

for f in glob.glob(dirname + "/*.xlsx"):
    try:
       pd.read_excel(f)
    except Warning as w:
        print(f)