Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does pandas count the missing values of a column or row?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to count the missing values of a column or row by pandas". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how pandas counts the missing values of a column or row.

Count the number of missing values in a column or row. Use isnull () import pandas as pd# to first import data df = pd.read_csv ('123.csv', encoding='gbk') # to calculate the number of missing values in each row of data That is, the missing value rows_null = df.isnull (). Sum (axis=1) # is the missing value col_null = df.isnull (). Sum (axis=0) # counts the missing value of the entire df all_null = df.isnull (). Sum (). Sum () # counts the missing value of a column idx_null = df ['column name'] .isnull (). Sum (axis=0) 2. Use countimport pandas as pd# to first import data df = pd.read_csv ('123.csv', encoding='gbk') # to calculate how many non-empty values each row of data has That is, non-null values by row rows_not_null = df.count (axis=1) # the following are column-by-column non-null values cols_not_null = df.count (axis=0) cols_null = df.shape [1]-cols_not_null# non-null values col_not_null = df ['column name'] .count (axis=0) use pandas to deal with missing values def missing_values (dataframe): missing_ratio = ( Dataframe.isnull (). Sum () / len (dataframe) * 100 missing_ratio = missing_ratio.drop (missing_ ratio [missing _ ratio = = 0] .index). Sort_values (ascending=False) missing_count = dataframe.isnull (). Sum () missing_count = missing_count.drop (missing_ count [missing _ count = = 0] .index). Sort_values (ascending=False) info = pd.DataFrame ({'Missing Ratio': missing_ratio) 'Missing Count': missing_count}) return info to this point I believe you have a deeper understanding of "how pandas counts the missing values of a column or row". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report