Below I will share with you an article in Python that solves the problem of pandas processing missing values as empty strings. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together
Trampling records:
When using pandas to handle missing values in csv, I found a strange bug, which is when opening it in excel csv file, some grids obviously don’t have anything. Of course, I thought of using pandas’ dropna() or fillna() to deal with missing values.
But after pandas read the csv file, it found that isnull() in the empty place turned out to be false, which means that there is something in that place. . .
Later, after investigation, it was found that there was an empty string in a place where there seemed to be nothing, so pandas believed that there was not a missing value, so it could not be processed with dropna() or fillna().
Solution: First use regular expressions to match the spaces, then replace them all with NULL, and then specify read_csv (na_values='NULL) when reading csv with pandas ') is to treat NULL as nan, and then you can use dropna() or fillna() to process it
The above python solution to the problem of pandas processing missing values as empty strings is shared by the editor I’ve given you all the content, I hope it can give you a reference, and I hope you will support Script House more.
The above is the detailed content of Python solves the problem of pandas processing missing values as empty strings. For more information, please follow other related articles on the PHP Chinese website!