python resolves an issue where pandas handles missing values as empty strings

Source: Internet
Author: User
The following for everyone to share a Python solution pandas processing missing value is an empty string problem, has a good reference value, I hope to help you. Come and see it together.

Pit Record:

Use pandas to do CSV missing value processing time found strange bug, that is, Excel open CSV file, obviously there is nothing in the lattice, of course, I think with pandas Dropna () or Fillna () to deal with the missing values.

But pandas read the CSV file and found that empty place IsNull () unexpectedly is false, that is the place there is something ...

Later after the investigation found that nothing seems to have empty strings, so Pandas think there is no missing value, so you can not use Dropna () or Fillna () to deal with.

Solution: First use the regular to match the space, and then replace all the null, and then read the CSV with pandas to specify Read_csv (na_values= ' Null ') means that null is treated as Nan and can then be processed with Dropna () or Fillna ().

Above this python solve pandas processing missing value is empty string of the problem is small part to share all the content of everyone, hope to give you a reference, also hope that we support the script home.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.