Usage of Python Dropna

Source: Internet
Author: User

"""
Return object with labels in given axis omitted where alternately any
Or all of the data is missing

Parameters
----------
Axis: {0 or ' index ', 1 or ' columns '}, or tuple/list thereof
Pass tuple or list to drop on multiple axes
How: {"Any", ' all '}
* Any:if any NA values is present, drop that label
* All:if All values is NA, drop that label
Thresh:int, default None
int value:require that many non-na values
Subset:array-like
Labels along other axis to consider, e.g. if is dropping rows
These would is a list of columns to include
Inplace:boolean, default False
If True, do Operation InPlace and return None.

Returns
-------
Dropped:dataframe

Examples
--------
>>> df = PD. DataFrame ([[Np.nan, 2, Np.nan, 0], [3, 4, Np.nan, 1],
... [Np.nan, Np.nan, Np.nan, 5]],
... columns=list (' ABCD '))
>>> DF
A B C D
0 Nan 2.0 nan 0
1 3.0 4.0 NaN 1
2 Nan Nan nan 5

Drop the columns where all elements is Nan:

>>> Df.dropna (Axis=1, how= ' all ')
A B D
0 NaN 2.0 0
1 3.0 4.0 1
2 Nan nan 5

Drop the columns where any of the elements is Nan

>>> Df.dropna (Axis=1, how= ' any ')
D
0 0
1 1
2 5

Drop the rows where all of the elements is Nan
(There is no row-to-drop, so DF stays the same):

>>> Df.dropna (axis=0, how= ' all ')
A B C D
0 Nan 2.0 nan 0
1 3.0 4.0 NaN 1
2 Nan Nan nan 5

Keep only the rows with at least 2 Non-na values:

>>> Df.dropna (thresh=2)
A B C D
0 Nan 2.0 nan 0
1 3.0 4.0 NaN 1

"""

Usage of Python Dropna

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.