In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Python pandas how to delete the specified row / column data, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
1. Filter out missing data dropna () import pandas as pdimport numpy as npdf=pd.DataFrame ({"record": [np.nan, "sub-health | Pan Guang | 45 years old", "disease | Zhang Si", np.nan], "date": [np.nan,20210102,20210103,20210104]}, index= ["one", "two", "three", "four"])
1) filter out all lines containing nan values df.dropna () # default axis=0
2) filter out all columns containing nan values df.dropna (axis=1)
3) filter out the row Df.dropna whose elements are nan values (axis=0,how= "all")
4) filter out columns in which all elements are nan values.
5) filter the missing row Df.dropna in the specified column (subset= ["record"], axis=0)
If you need to change the original data directly, you need to set the parameter inplace=True.
two。 Delete the duplicate value drop_duplicates () df=pd.DataFrame ({'state': [1, 1, 1, 2, 2, 2, 2],' pop': ['a, 2, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2],',
Syntax: drop_duplicates (subset,keep,inplace), where parameter keep: {'first','last',False}, default' first'
First: keep the first duplicates and delete the second and subsequent duplicates.
Last: keep the last duplicates and delete the previous duplicates.
"false": delete all duplicates.
1) keep= "first" df.drop_duplicates (keep= "first")
2) keep= "last" df.drop_duplicates (keep= "last")
3) keep=Falsedf.drop_duplicates (keep=False)
4) delete the row df.drop _ duplicates corresponding to the duplicates in the specified column (subset= ["state"], keep= "first")
If you need to change the original data directly, you need to set the parameter inplace=True.
3. Delete rows and columns drop () df=pd.DataFrame (np.arange (16) .reshape (4p4), columns= ["one", "two", "three", "four"]) according to the specified conditions
1)。 Delete the specified column df.drop (["one"], axis=1)
Alternatively, you can delete a specified column through del df ["one"], but this method is not recommended because it makes changes directly on the source data by default.
2)。 Delete the specified line df.drop ([0], axis=0)
If you need to change the original data directly, you need to set the parameter inplace=True.
After reading the above, have you mastered how Python pandas deletes specified row / column data? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.