How to Drop Rows with NaN Values in Pandas DataFrame - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Saturday, May 20, 2023

How to Drop Rows with NaN Values in Pandas DataFrame

 

In this article, you’ll see how to drop rows with NaN values in Pandas DataFrame

 


 

 

 

 

 

 

Figure 1

 


 

 

 

 

 

 

Figure 2

 

 

import pandas as pd

 

dataFrame = pd.DataFrame({

    'values1': ['Bahadir','23','34','Melissa','44','89'],

    'values2': ['54','38','Antony','24','35','Julia']

                         })

 

dataFrame = dataFrame.apply (pd.to_numeric, errors='coerce')

dataFrame = dataFrame.dropna()

dataFrame = dataFrame.reset_index(drop=True)

 

print (dataFrame)

 

Hope to see you in the next article. Happy coding


No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...