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)05/31 Report--
This article mainly introduces the relevant knowledge of how to deal with Python missing values, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to deal with Python missing values. Let's take a look at it.
First, build a DataFrame with missing values, as follows:
Import pandas as pdimport numpy as npdata = pd.DataFrame ([[1rect np.nanmae3], [np.nan,5,np.nan]], columns = ['axiajiaoyuanjia]) print (data)
Can you see that? Np.nan means Nan value, which means null value.
There is a function in numpy that can be used to see null values. No, there are two functions, isnull () and isna ().
Let's try their effects separately:
Import pandas as pdimport numpy as npdata = pd.DataFrame ([[1rect np.nanmae3], [np.nan,5,np.nan]], columns = ['axiajiaoyuzhongjia']) data.isnull () data.isna ()
As you can see, the function of these two functions is to determine whether the data is null or not, and if so, return true, either false.
Usually, there are two ways to deal with null values, one is to delete null values, and the other is to fill it in. Let's start with the first one, delete null values, and we can delete null values with the function dropna (). Note that it deletes the entire line that contains null values. For example:
Import pandas as pdimport numpy as npdata = pd.DataFrame ([[1rect np.nanmae3], [np.nan,5,np.nan]], columns = ['axiajiajiaoyuanjia']) data.dropna ()
After using the drop function in the above example, there is nothing left!
We can set to delete when each row has more than 2 null values (less than 2 reservations), and then use the parameter thresh of dropna ().
There are many ways to supplement null values, such as mean supplement, median supplement, etc. We need to use the function fillna (). For example, we populate the data above with the mean
The code is as follows:
Import pandas as pdimport numpy as npdata = pd.DataFrame ([[1rect np.nanmae3], [np.nan,5,np.nan]], columns = ['axiajiaoyuzhongjia]) data.fillna (data.mean ())
The result of the code running is as follows, and you can see that the null values are filled with the mean of the corresponding column.
This is the end of the article on "how to deal with Python missing values". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to deal with Python missing values". If you want to learn more knowledge, you are welcome to follow the industry information channel.
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.