🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 160 (from laksa087)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
2 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/
Last Crawled2026-04-05 00:15:11 (2 days ago)
First Indexed2025-07-02 11:54:55 (9 months ago)
HTTP Status Code200
Meta TitleWhat is pandas dropna()? - IONOS
Meta DescriptionWith the pandas dropna() function, you can clean datasets according to your needs. We show you how it works here.
Meta Canonicalnull
Boilerpipe Text
The Python pandas DataFrame.dropna() function is used to remove all rows or columns con­tain­ing missing values (NaN) from a DataFrame. This makes it es­pe­cial­ly crucial for preparing and cleaning data . What is the syntax for pandas dropna() ? The dropna() function accepts up to five pa­ra­me­ters . Here’s its syntax: DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False, ignore_index=False) python Important pa­ra­me­ters for dropna() You can use pa­ra­me­ters to influence the behavior of the pandas DataFrame.dropna() function. Here’s an overview of the most important ones: Parameter De­scrip­tion Default Value axis De­ter­mines whether rows (0 or index ) or columns (1 or columns ) will be removed 0 how Specifies whether all ( all ) or only some ( any ) values must be NaN any thresh Specifies the minimum number of non-NaN values a row or column must have to avoid being removed; cannot be combined with how optional subset Specifies which rows or columns should be con­sid­ered optional inplace De­ter­mines whether the operation is performed on the original DataFrame False ignore_index If True , the remaining axis is labeled from 0 to n-1 False How to use pandas DataFrame.dropna() Pandas dropna() is used to clean data before it’s analyzed. The removal of rows or columns with missing values helps to prevent biases in sta­tis­ti­cal eval­u­a­tions. Since missing values can also lead to problems with data vi­su­al­iza­tion, using the function is also ad­van­ta­geous when creating charts and reports. Removing rows with missing values In the following example, we’ll take a look at a DataFrame con­tain­ing NaN values: import pandas as pd import numpy as np # Creating a DataFrame with sample data data = { 'A': [1, 2, np.nan, 4], 'B': [5, np.nan, np.nan, 8], 'C': [9, 10, 11, 12] } df = pd.DataFrame(data) print(df) python The DataFrame looks like this: A B C 0 1.0 5.0 9 1 2.0 NaN 10 2 NaN NaN 11 3 4.0 8.0 12 Next, we’re going to apply the pandas dropna() function: ## Remove all rows that contain at least one NaN value df_cleaned = df.dropna() print(df_cleaned) python Running the code above produces the following result: A B C 0 1.0 5.0 9 3 4.0 8.0 12 Since all the other rows contain NaN values, only the zeroth and third rows remain. Removing columns with missing values Similarly, you can remove columns with missing values by setting the axis parameter to 1: ## Remove all columns that contain at least one NaN value df_cleaned_columns = df.dropna(axis=1) print(df_cleaned_columns) python Column C is the only column that remains, since it’s the only one that doesn’t contain NaN values: C 0 9 1 10 2 11 3 12 Using thresh If you want to remove rows that contain fewer than two non-NaN values, you can use the thresh parameter: ## Only keeps rows that have 2 or more non-NaN values df_thresh = df.dropna(thresh=2) print(df_thresh) python Running the code produces the following output: A B C 0 1.0 5.0 9 1 2.0 NaN 10 3 4.0 8.0 12 Row 1 is not removed from the output because it contains 2 non-NaN values (2.0 and 10). Using subset The subset parameter allows you to specify the columns where the program should look for missing values. Only rows that contain missing values in the columns that have been specified will be removed. ## Removes all rows where column A contains a NaN value df_subset = df.dropna(subset=['A']) print(df_subset) python Here, only the second row is removed. The NaN value in the first row is ignored due to the subset parameter, which only takes column A into con­sid­er­a­tion: A B C 0 1.0 5.0 9 1 2.0 NaN 10 3 4.0 8.0 12
Markdown
[Skip to Main Content](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/#main-content) [Digital Guide](https://www.ionos.com/digitalguide/) IONOS Products IONOS Products Close - Domains & SSL - [Domain Names](https://www.ionos.com/domains/domain-names) - [Free Domain Transfer](https://www.ionos.com/domains/domain-transfer) - [.com Domain](https://www.ionos.com/domains/com-domain) - [Free Domain](https://www.ionos.com/domains/free-domain-name) - [New Top-Level Domains](https://www.ionos.com/domains/new-top-level-domains) - [SSL Cer­tifi­cate](https://www.ionos.com/security/ssl-certificate) - [Domain Security](https://www.ionos.com/domains/domain-guard) - Websites & eCommerce - [Website Builder](https://www.ionos.com/websites/website-builder) - [Web Design Services](https://www.ionos.com/websites/custom-made-website) - [Website Migration Service](https://www.ionos.com/websites/website-migration-service) - [Search Engine Op­ti­miza­tion Tool](https://www.ionos.com/marketing/rankingcoach) - [Google Ads Man­age­ment Service](https://www.ionos.com/marketing/google-ads-management) - [AI Rep­u­ta­tion Man­age­ment](https://www.ionos.com/marketing/online-reputation-management) - [eCommerce Website Builder](https://www.ionos.com/ecommerce-solutions/ecommerce-website-builder) - [eCommerce Website Design](https://www.ionos.com/ecommerce-solutions/ecommerce-website-design) - [eCommerce Plugin](https://www.ionos.com/ecommerce-solutions/ecommerce-plugin) - [Social Buy Button](https://www.ionos.com/ecommerce-solutions/social-buy-button) - Hosting & WordPress - [Web Hosting](https://www.ionos.com/hosting/web-hosting) - [Hosting for WordPress](https://www.ionos.com/hosting/managed-wordpress) - [Hosting for WooCom­merce](https://www.ionos.com/ecommerce-solutions/woocommerce-hosting) - [Jamstack Hosting](https://www.ionos.com/hosting/jamstack) - [Joomla! Hosting](https://www.ionos.com/hosting/joomla-hosting) - [Deploy Now](https://www.ionos.com/hosting/deploy-now) - [VPS Hosting](https://www.ionos.com/servers/vps) - Office - [Business Email](https://www.ionos.com/office-solutions/create-an-email-address) - [Email Marketing Software](https://www.ionos.com/marketing/email-marketing) - [Email Archiving Solutions](https://www.ionos.com/office-solutions/email-archiving) - [Hosted Microsoft Exchange](https://www.ionos.com/office-solutions/microsoft-exchange) - [Microsoft 365 Business](https://www.ionos.com/office-solutions/microsoft-office) - [Google Workspace](https://www.ionos.com/office-solutions/google-workspace) - [HiDrive Cloud Storage](https://www.ionos.com/office-solutions/hidrive-cloud-storage) - [My­De­fend­er](https://www.ionos.com/office-solutions/mydefender) - Servers - [Bare Metal Server](https://www.ionos.com/servers/bare-metal-servers) - [Cloud Backup](https://www.ionos.com/cloud/cloud-backup) - [Cloud Server](https://www.ionos.com/cloud/cloud-servers) - [Dedicated Servers](https://www.ionos.com/servers/dedicated-servers) - [Free VPS](https://www.ionos.com/servers/free-vps) - [Managed Ku­ber­netes](https://cloud.ionos.com/managed/kubernetes) - [Rent a Server](https://www.ionos.com/servers/rent-a-server) - [Windows VPS](https://www.ionos.com/servers/windows-vps) - [VPS Hosting](https://www.ionos.com/servers/vps) - [IONOS Cloud](https://cloud.ionos.com/) - [IONOS Cloud Object Storage](https://cloud.ionos.com/storage/object-storage) - Tools - [Business Name Generator](https://www.ionos.com/tools/business-name-generator) - [AI Domain Name Generator](https://www.ionos.com/ai-domain-name-generator) - [Logo Creator](https://www.ionos.com/tools/logo-maker) - [Favicon Generator](https://www.ionos.com/tools/favicon-generator) - [Whois Lookup](https://www.ionos.com/tools/whois-domain-lookup) - [Website Checker](https://www.ionos.com/tools/website-checker) - [SEO Check](https://www.ionos.com/tools/seo-check) - [SSL Checker](https://www.ionos.com/tools/ssl-checker) - [IP Address Check](https://www.ionos.com/tools/ip-address) Main menu Close IONOS Products - [Websites](https://www.ionos.com/digitalguide/websites/ "Websites") - [Website creation](https://www.ionos.com/digitalguide/websites/website-creation/ "Website creation") - [Web design](https://www.ionos.com/digitalguide/websites/web-design/ "Web design") - [Web de­vel­op­ment](https://www.ionos.com/digitalguide/websites/web-development/ "Web development") - [Digital law](https://www.ionos.com/digitalguide/websites/digital-law/ "Digital law") - [Hosting](https://www.ionos.com/digitalguide/hosting/ "Hosting") - [CMS](https://www.ionos.com/digitalguide/hosting/cms/ "CMS") - [Blogs](https://www.ionos.com/digitalguide/hosting/blogs/ "Blogs") - [Technical matters](https://www.ionos.com/digitalguide/hosting/technical-matters/ "Technical matters") - [Server](https://www.ionos.com/digitalguide/server/ "Server") - [Know-how](https://www.ionos.com/digitalguide/server/know-how/ "Know-how") - [Con­fig­u­ra­tion](https://www.ionos.com/digitalguide/server/configuration/ "Configuration") - [Security](https://www.ionos.com/digitalguide/server/security/ "Security") - [Tools](https://www.ionos.com/digitalguide/server/tools/ "Tools") - [Domains](https://www.ionos.com/digitalguide/domains/ "Domains") - [Domain ex­ten­sions](https://www.ionos.com/digitalguide/domains/domain-extensions/ "Domain extensions") - [Domain ad­min­is­tra­tion](https://www.ionos.com/digitalguide/domains/domain-administration/ "Domain administration") - [Domain news](https://www.ionos.com/digitalguide/domains/domain-news/ "Domain news") - [Domain tips](https://www.ionos.com/digitalguide/domains/domain-tips/ "Domain tips") - [Online marketing](https://www.ionos.com/digitalguide/online-marketing/ "Online marketing") - [Online sales](https://www.ionos.com/digitalguide/online-marketing/online-sales/ "Online sales") - [Search engine marketing](https://www.ionos.com/digitalguide/online-marketing/search-engine-marketing/ "Search engine marketing") - [Social media](https://www.ionos.com/digitalguide/online-marketing/social-media/ "Social media") - [Web analytics](https://www.ionos.com/digitalguide/online-marketing/web-analytics/ "Web analytics") - [E-mail](https://www.ionos.com/digitalguide/e-mail/ "E-mail") - [E-mail marketing](https://www.ionos.com/digitalguide/e-mail/e-mail-marketing/ "E-mail marketing") - [E-mail security](https://www.ionos.com/digitalguide/e-mail/e-mail-security/ "E-mail security") - [Technical matters](https://www.ionos.com/digitalguide/e-mail/technical-matters/ "Technical matters") - [Startup](https://www.ionos.com/digitalguide/startup/ "Startup") - [Get Started](https://www.ionos.com/digitalguide/startup/get-started/ "Get Started") - [Grow Your Business](https://www.ionos.com/digitalguide/startup/grow-your-business/ "Grow Your Business") - [Pro­duc­tiv­i­ty](https://www.ionos.com/digitalguide/startup/productivity/ "Productivity") ![Image: ION\_US\_DG-MyWebsite\_1200x628.jpg](https://www.ionos.com/digitalguide/fileadmin/_processed_/c/b/csm_US_offer_Fallback_MyWebsite_1200x628_fa9980e5ee.webp) ![Image: ION\_US\_DG-MyWebsite\_960x1200.jpg](https://www.ionos.com/digitalguide/fileadmin/_processed_/e/7/csm_US_offer_Fallback_MyWebsite_960x1200_0ada473d7e.webp) See plans Close 1. [IONOS](https://www.ionos.com/ "IONOS") 2. [Digital Guide](https://www.ionos.com/digitalguide/ "Digital Guide") 3. [Websites](https://www.ionos.com/digitalguide/websites/ "Websites") 4. [Web de­vel­op­ment](https://www.ionos.com/digitalguide/websites/web-development/ "Web development") 5. Python pandas: DataFrame dropna() # How to clean data in pandas with dropna() - [IONOS editorial team](https://www.ionos.com/experts/about-us/ "IONOS editorial team") 06/26/2025 3 mins - - [Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/ "Share on Facebook") - [Share on Twitter](https://twitter.com/intent/tweet?source=https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/&text=Python%20pandas%3A%20DataFrame%20dropna%28%29&hashtags=DigitalGuide&url=https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/ "Share on Twitter") - [Share on LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/ "Share on LinkedIn") - [Python Pandas](https://www.ionos.com/digitalguide/tags/python-pandas/) ![Image: How to clean data in pandas with dropna()](data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMSAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogICAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idHJhbnNwYXJlbnQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPgo8L3N2Zz4K) BEST-BACK­GROUNDSShut­ter­stock Contents - [What is the syntax for pandas dropna()?](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/#content-what-is-the-syntax-for-pandas-dropna) - [How to use pandas DataFrame.dropna()](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/#content-how-to-use-pandas-dataframedropna) The [Python pandas](https://www.ionos.com/digitalguide/websites/web-development/python-pandas/) `DataFrame.dropna()` function is used to remove all rows or columns con­tain­ing missing values (NaN) from a DataFrame. This makes it es­pe­cial­ly crucial for **preparing and cleaning data**. Web Hosting Hosting that scales with your ambitions - Stay online with 99.99% uptime and robust security - Add per­for­mance with a click as traffic grows - Includes free domain, SSL, email, and 24/7 support See plans ## What is the syntax for pandas `dropna()`? The `dropna()` function accepts **up to five pa­ra­me­ters**. Here’s its syntax: ``` DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False, ignore_index=False) ``` python ### Important pa­ra­me­ters for `dropna()` You can **use pa­ra­me­ters to influence the behavior** of the pandas `DataFrame.dropna()` function. Here’s an overview of the most important ones: | **Parameter** | **De­scrip­tion** | **Default Value** | |---|---|---| | `axis` | De­ter­mines whether rows (0 or `index`) or columns (1 or `columns`) will be removed | 0 | | `how` | Specifies whether all (`all`) or only some (`any`) values must be NaN | `any` | | `thresh` | Specifies the minimum number of non-NaN values a row or column must have to avoid being removed; cannot be combined with `how` | optional | | `subset` | Specifies which rows or columns should be con­sid­ered | optional | | `inplace` | De­ter­mines whether the operation is performed on the original DataFrame | `False` | | `ignore_index` | If `True`, the remaining axis is labeled from 0 to n-1 | `False` | ## How to use pandas `DataFrame.dropna()` Pandas `dropna()` is used to clean data before it’s analyzed. The removal of rows or columns with missing values helps to **prevent biases** in sta­tis­ti­cal eval­u­a­tions. Since missing values can also lead to problems with data vi­su­al­iza­tion, using the function is also **ad­van­ta­geous when creating charts** and reports. ### Removing rows with missing values In the following example, we’ll take a look at a DataFrame con­tain­ing NaN values: ``` import pandas as pd import numpy as np # Creating a DataFrame with sample data data = { 'A': [1, 2, np.nan, 4], 'B': [5, np.nan, np.nan, 8], 'C': [9, 10, 11, 12] } df = pd.DataFrame(data) print(df) ``` python The DataFrame looks like this: ``` A B C 0 1.0 5.0 9 1 2.0 NaN 10 2 NaN NaN 11 3 4.0 8.0 12 ``` Next, we’re going to apply the pandas `dropna()` function: ``` ## Remove all rows that contain at least one NaN value df_cleaned = df.dropna() print(df_cleaned) ``` python Running the code above produces the following result: ``` A B C 0 1.0 5.0 9 3 4.0 8.0 12 ``` Since all the other rows contain NaN values, only the zeroth and third rows remain. ### Removing columns with missing values Similarly, you can remove columns with missing values by setting the `axis` parameter to 1: ``` ## Remove all columns that contain at least one NaN value df_cleaned_columns = df.dropna(axis=1) print(df_cleaned_columns) ``` python Column C is the only column that remains, since it’s the only one that doesn’t contain NaN values: ``` C 0 9 1 10 2 11 3 12 ``` ### Using `thresh` If you want to remove rows that contain fewer than two non-NaN values, you can use the `thresh` parameter: ``` ## Only keeps rows that have 2 or more non-NaN values df_thresh = df.dropna(thresh=2) print(df_thresh) ``` python Running the code produces the following output: ``` A B C 0 1.0 5.0 9 1 2.0 NaN 10 3 4.0 8.0 12 ``` Row 1 is not removed from the output because it contains 2 non-NaN values (2.0 and 10). ### Using `subset` The `subset` parameter allows you to specify the columns where the program should look for missing values. Only rows that contain missing values in the columns that have been specified will be removed. ``` ## Removes all rows where column A contains a NaN value df_subset = df.dropna(subset=['A']) print(df_subset) ``` python Here, only the second row is removed. The NaN value in the first row is ignored due to the subset parameter, which only takes column A into con­sid­er­a­tion: ``` A B C 0 1.0 5.0 9 1 2.0 NaN 10 3 4.0 8.0 12 ``` Related tags - [Python Pandas](https://www.ionos.com/digitalguide/tags/python-pandas/) [Go to Main Menu](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-dropna/#navigation-main) ### Related Products ![Image: deploy-now.svg](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Product_Icons/deploy-now.svg) Deploy Now See plans ![Image: ION\_US\_DG-MyWebsite\_1200x1200.jpg](https://www.ionos.com/digitalguide/fileadmin/_processed_/a/8/csm_US_offer_Fallback_MyWebsite_1200x1200_2c33f01cc4.webp) ![Image: ION\_US\_DG-MyWebsite\_1200x1200.jpg](https://www.ionos.com/digitalguide/fileadmin/_processed_/a/8/csm_US_offer_Fallback_MyWebsite_1200x1200_2c33f01cc4.webp) ### 10 Years Digital Guide: A Success Story Ex­pe­ri­ence the Evolution ### Turn calls into revenue: AI re­cep­tion­ist Free webinar Save my spot #### Popular Articles ##### [Domain Trading: How to sell a domain name](https://www.ionos.com/digitalguide/domains/domain-news/get-rich-by-selling-domain-names/ "Domain Trading: How to sell a domain name") Buying and selling domains can be lucrative – if you know how to go about it. We will… Read more ##### [What Nextcloud al­ter­na­tives are there? 5 options compared](https://www.ionos.com/digitalguide/server/tools/nextcloud-alternatives/ "What Nextcloud alternatives are there? 5 options compared") Looking for Nextcloud al­ter­na­tives but unsure how they measure up? We take a look at 5… Read more ##### [What are the best online backup services? A com­par­i­son](https://www.ionos.com/digitalguide/server/tools/the-best-online-backup-services/ "What are the best online backup services? A comparison") Secure your data reliably in the cloud! These 7 online backup services offer safe and… Read more ##### [How to upgrade Debian 13 step by step](https://www.ionos.com/digitalguide/server/configuration/debian-13-upgrade/ "How to upgrade Debian 13 step by step") This guide shows you how to perform a Debian 13 upgrade, prepare your system, and avoid… Read more ##### [Al­ter­na­tives for InDesign: 4 free tools](https://www.ionos.com/digitalguide/websites/web-design/free-alternatives-to-adobe-indesign/ "Alternatives for InDesign: 4 free tools") Desktop pub­lish­ing with Adobe too expensive? There are numerous al­ter­na­tives for InDesign… Read more ### Related articles ![Image: How to loop through DataFrames with pandas iterrows()](https://www.ionos.com/digitalguide/fileadmin/_processed_/1/6/csm_code-editoren-t_6ea6ef267f.webp)BEST-BACK­GROUNDSShut­ter­stock ### [How to loop through DataFrames with pandas iterrows()](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-iterrows/ "How to loop through DataFrames with pandas iterrows()") Pandas DataFrame.iterrows() is a helpful function for looping through rows in a DataFrame, es­pe­cial­ly when you need to process data row by row. This is es­pe­cial­ly useful for cal­cu­la­tions or con­di­tion­al logic. In this article, we’ll cover the syntax of panda iterrows() and show… - Python Pandas Read more ![Image: How to index pandas DataFrames](https://www.ionos.com/digitalguide/fileadmin/_processed_/e/4/csm_baukasten-t_8597781750.webp)Mr. Kosalshut­ter­stock ### [How to index pandas DataFrames](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-indexing/ "How to index pandas DataFrames") Pandas DataFrame indexing is a powerful tool for efficient and effective data handling. With various methods, you can target specific data and subsets of your DataFrame. In this article, we’ll explore what the pandas DataFrame index is, how to access column and row data using… - Python Pandas Read more ![Image: What is Python pandas any() and how does it work?](https://www.ionos.com/digitalguide/fileadmin/_processed_/e/4/csm_baukasten-t_8597781750.webp)Mr. Kosalshut­ter­stock ### [What is Python pandas any() and how does it work?](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-any/ "What is Python pandas any() and how does it work?") In pandas, the DataFrame any() method is an efficient tool to quickly check if there is at least one true value along an axis of a DataFrame. This method is es­pe­cial­ly helpful for data analysis and val­i­da­tion. In this article, we’ll show you what the syntax for this function is,… - Python Pandas Read more ![Image: How to use Pandas DataFrame to manipulate tables quickly in Python](https://www.ionos.com/digitalguide/fileadmin/_processed_/2/5/csm_garuda-linux-t_d34e04d620.webp)ESB Pro­fes­sion­alshut­ter­stock ### [How to use Pandas DataFrame to ma­nip­u­late tables quickly in Python](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe/ "How to use Pandas DataFrame to manipulate tables quickly in Python") The Pandas module is one of the most powerful tools for data ma­nip­u­la­tion in Python. One of the central data struc­tures in Pandas is the DataFrame. DataFrames can be used to ma­nip­u­late two-di­men­sion­al, struc­tured data ef­fi­cient­ly. We explain the structure of the data structure as… - Python Pandas Read more ![Image: What is the Python pandas property iloc\[\]?](https://www.ionos.com/digitalguide/fileadmin/_processed_/9/1/csm_docker-images-erstellen_830c6ccaca.webp)UndreyShut­ter­stock ### [What is the Python pandas property iloc\[\]?](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-iloc/ "What is the Python pandas property iloc[]?") When working with DataFrames in Python pandas, not all rows or columns of a DataFrame are always relevant for data analysis. The pandas DataFrame property iloc\[\] is a useful tool for selecting rows or columns using their indices. In this article, we’ll take a look at the syntax… - Python Pandas Read more ![Image: How to calculate averages with pandas mean()](https://www.ionos.com/digitalguide/fileadmin/_processed_/f/9/csm_code-screen_t_f488e48ec2.webp)REDPIXEL.PLShut­ter­stock ### [How to calculate averages with pandas mean()](https://www.ionos.com/digitalguide/websites/web-development/python-pandas-dataframe-mean/ "How to calculate averages with pandas mean()") The pandas \`DataFrame.mean()\` function cal­cu­lates averages in a DataFrame. It can be used to find average values for rows or columns, and offers flex­i­bil­i­ty when it comes to handling NaN values. In this article, we’ll look at the syntax of the function, the pa­ra­me­ters it takes… - Python Pandas Read more Your digital partner - [About IONOS](https://www.ionos.com/about "About IONOS") - [Careers](https://ionos.applicantpool.com/jobs/ "Careers") - [Newsroom](https://www.ionos.com/newsroom/ "Newsroom") - [Help Center](https://www.ionos.com/help/ "Help Center") - [Terms and Con­di­tions](https://www.ionos.com/terms-gtc/general-terms-and-conditions/ "Terms and Conditions") - [Privacy Policy](https://www.ionos.com/terms-gtc/privacy-policy/ "Privacy Policy") © 2026 [IONOS Inc.](https://www.ionos.com/ "IONOS Inc.") - [RSS](https://www.ionos.com/digitalguide/websites/web-development/feed.rss "RSS") - [LinkedIn](https://ionos.ly/IONOS_IN "LinkedIn") - [Facebook](https://ionos.ly/IONOS_FB_US "Facebook") - [YouTube](https://ionos.ly/IONOS_YT_US "YouTube") We use cookies on our website to provide you with the best possible user ex­pe­ri­ence. By con­tin­u­ing to use our website or services, you agree to their use. [More In­for­ma­tion.](https://www.ionos.com/cookies) OK
Readable Markdown
The [Python pandas](https://www.ionos.com/digitalguide/websites/web-development/python-pandas/) `DataFrame.dropna()` function is used to remove all rows or columns con­tain­ing missing values (NaN) from a DataFrame. This makes it es­pe­cial­ly crucial for **preparing and cleaning data**. ## What is the syntax for pandas `dropna()`? The `dropna()` function accepts **up to five pa­ra­me­ters**. Here’s its syntax: ``` DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False, ignore_index=False) ``` python ### Important pa­ra­me­ters for `dropna()` You can **use pa­ra­me­ters to influence the behavior** of the pandas `DataFrame.dropna()` function. Here’s an overview of the most important ones: | **Parameter** | **De­scrip­tion** | **Default Value** | |---|---|---| | `axis` | De­ter­mines whether rows (0 or `index`) or columns (1 or `columns`) will be removed | 0 | | `how` | Specifies whether all (`all`) or only some (`any`) values must be NaN | `any` | | `thresh` | Specifies the minimum number of non-NaN values a row or column must have to avoid being removed; cannot be combined with `how` | optional | | `subset` | Specifies which rows or columns should be con­sid­ered | optional | | `inplace` | De­ter­mines whether the operation is performed on the original DataFrame | `False` | | `ignore_index` | If `True`, the remaining axis is labeled from 0 to n-1 | `False` | ## How to use pandas `DataFrame.dropna()` Pandas `dropna()` is used to clean data before it’s analyzed. The removal of rows or columns with missing values helps to **prevent biases** in sta­tis­ti­cal eval­u­a­tions. Since missing values can also lead to problems with data vi­su­al­iza­tion, using the function is also **ad­van­ta­geous when creating charts** and reports. ### Removing rows with missing values In the following example, we’ll take a look at a DataFrame con­tain­ing NaN values: ``` import pandas as pd import numpy as np # Creating a DataFrame with sample data data = { 'A': [1, 2, np.nan, 4], 'B': [5, np.nan, np.nan, 8], 'C': [9, 10, 11, 12] } df = pd.DataFrame(data) print(df) ``` python The DataFrame looks like this: ``` A B C 0 1.0 5.0 9 1 2.0 NaN 10 2 NaN NaN 11 3 4.0 8.0 12 ``` Next, we’re going to apply the pandas `dropna()` function: ``` ## Remove all rows that contain at least one NaN value df_cleaned = df.dropna() print(df_cleaned) ``` python Running the code above produces the following result: ``` A B C 0 1.0 5.0 9 3 4.0 8.0 12 ``` Since all the other rows contain NaN values, only the zeroth and third rows remain. ### Removing columns with missing values Similarly, you can remove columns with missing values by setting the `axis` parameter to 1: ``` ## Remove all columns that contain at least one NaN value df_cleaned_columns = df.dropna(axis=1) print(df_cleaned_columns) ``` python Column C is the only column that remains, since it’s the only one that doesn’t contain NaN values: ``` C 0 9 1 10 2 11 3 12 ``` ### Using `thresh` If you want to remove rows that contain fewer than two non-NaN values, you can use the `thresh` parameter: ``` ## Only keeps rows that have 2 or more non-NaN values df_thresh = df.dropna(thresh=2) print(df_thresh) ``` python Running the code produces the following output: ``` A B C 0 1.0 5.0 9 1 2.0 NaN 10 3 4.0 8.0 12 ``` Row 1 is not removed from the output because it contains 2 non-NaN values (2.0 and 10). ### Using `subset` The `subset` parameter allows you to specify the columns where the program should look for missing values. Only rows that contain missing values in the columns that have been specified will be removed. ``` ## Removes all rows where column A contains a NaN value df_subset = df.dropna(subset=['A']) print(df_subset) ``` python Here, only the second row is removed. The NaN value in the first row is ignored due to the subset parameter, which only takes column A into con­sid­er­a­tion: ``` A B C 0 1.0 5.0 9 1 2.0 NaN 10 3 4.0 8.0 12 ```
Shard160 (laksa)
Root Hash16735937331567176760
Unparsed URLcom,ionos!www,/digitalguide/websites/web-development/python-pandas-dataframe-dropna/ s443