PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 16, 2022

[FIXED] How to print the name of document that during the reading to pandas data frame displays the warning

 July 16, 2022     pandas, python, warnings     No comments   

Issue

I have this warning during the reading excel document to data frame:

*

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 reading all documents from a particular folder I use this:

`for f in glob.glob(dirname + "/*.xlsx")`:
    #where dirname is the path to the folder, and then for reading documents:
    pd.read_excel(f)

I want to print the name of the document which causes warning appearance during its reading to the data frame.

How to do that?


Solution

import warnings
warnings.filterwarnings("error")

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


Answered By - Omkar Sabade
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing