Python solves the problem of pandas processing missing values ​​as empty strings

不言
Release: 2018-05-02 13:50:32
Original
5244 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template