Relatively new to Python, having challenges handling a Pandas exception in PyCharm Professional. I'm trying to read in a CSV using Pandas:
import pandas as pd
df = pd.read_csv('file.csv', index_col=False)
and I get this message:
pydev_umd:1: DtypeWarning: Columns (56) have mixed types. Specify dtype option on import of set low_memory = False
I know why the warning arises. The CSV is an output from another program that will, very rarely, omit columns from the interior of CSV's last row, causing subsequent columns to shift and screw up the dtypes. I can't change the other program's behavior, so my thought was to add error-handling in Python when the DtypeWarning occurs.
I don't have much experience with exceptions, but after seeing a similar question here, I tried:
try:
df = pd.read_csv('file.csv', index_col=False)
except pd.errors.DtypeWarning:
print("Handling Dtype warning!")
It doesn't seem to catch the warning; I still get the same df
and the same message:
pydev_umd:1: DtypeWarning: Columns (56) have mixed types. Specify dtype option on import of set low_memory = False
I'm at a loss. I'd appreciate any suggestions what to try next.