Posts

Showing posts with the label Manipulation

Data Cleaning and Manipulation in Pandas:

  Data Cleaning and Manipulation in Pandas: Handling missing values: In real-world datasets, missing values are quite common. Pandas provides various functions to handle missing values, such as isna() , fillna() , and dropna() . For example: python Copy code import pandas as pd  data = { 'Name' : [ 'John' , 'Alice' , 'Bob' , 'Mary' ], 'Age' : [ 25 , 30 , None , 35 ]}  df = pd.DataFrame(data)  df.fillna( 0 , inplace= True )  print (df) This will fill all the missing values in the DataFrame with 0. Data filtering: Data filtering is the process of selecting rows or columns based on some condition. Pandas provides various ways to filter data, such as using boolean indexing, query() method, and loc[] and iloc[] methods. For example: bash Copy code import pandas as pd  data = { 'Name' : [ 'John' , 'Alice' , 'Bob' , 'Mary' ], 'Age' : [25, 30, 35, 40]}  df = pd.DataFrame(data)  filtered_data =