原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12254786.html

 

NA handling methods

pandas NA handling

 

isnull, not null

pandas NA handling

The built-in Python None value is also treated as NA in object arrays

pandas NA handling

 

dropna

There are a few ways to filter out missing data. While you always have the option to do it by hand using pandas.isnull and boolean indexing, the dropna can be helpful. On a Series, it returns the Series with only the non-null data and index values.

pandas NA handling 

With DataFrame objects, things are a bit more complex. You may want to drop rows or columns that are all NA or only those containing any NAs.

dropna by default drops any row containing a missing value.

pandas NA handling

 

To drop columns in the same way, pass axis=1 

pandas NA handling

thresh - Require that many non-NA value

pandas NA handling

pandas NA handling

 

fillna

pandas NA handling

 

Calling fillna with a dict, you can use a different fill value for each column

pandas NA handling

 

fillna returns a new object, but you can modify the existing object in-place

pandas NA handling

 

method{‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}, default None

pandas NA handling

pandas NA handling 

 

Reference

Python for Data Analysis Second Edition

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.isnull.html

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.notnull.html

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dropna.html

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.fillna.html

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.fillna.html

 

相关文章:

  • 2022-02-05
  • 2022-02-19
  • 2021-10-23
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-09-11
  • 2021-05-13
猜你喜欢
  • 2021-12-04
  • 2021-06-14
  • 2022-01-17
  • 2021-08-10
  • 2022-03-02
  • 2022-02-22
  • 2021-07-25
相关资源
相似解决方案