0% found this document useful (0 votes)
5 views2 pages

Python Pandas DataFrame Guide

This document provides an overview of key concepts in Python programming using Pandas, including the definition of a DataFrame, how to create a Pandas Series from a dictionary, and strategies for handling missing values. It also explains the role of NumPy, the use of the isnull() function, and the steps for importing and exporting data with Pandas. Additionally, it emphasizes the importance of handling missing values in data preprocessing.

Uploaded by

arun tiwari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Python Pandas DataFrame Guide

This document provides an overview of key concepts in Python programming using Pandas, including the definition of a DataFrame, how to create a Pandas Series from a dictionary, and strategies for handling missing values. It also explains the role of NumPy, the use of the isnull() function, and the steps for importing and exporting data with Pandas. Additionally, it emphasizes the importance of handling missing values in data preprocessing.

Uploaded by

arun tiwari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Part B :- Unit 01 Python Programming

Question and Answer code 843 AI

1. What is a DataFrame in Pandas?

Answer: A dataframe is a data structure which is constructed with rows and


columns, just like an Excel spreadsheet or database. DataFrame works on
Tabular data; this table organises data into rows and columns.

2. How do you create a Pandas Series from a dictionary?

Answer: Pandas provides two data structures for manipulating data, series
and dataframes. In a series data structure, simply pass the dictionary to the
[Link]() function with dictionary keys, which will become the index and
values of the series. Example,

import pandas as pd

series1 = [Link]([10,20.30])

3. Name two strategies to handle missing values in a DataFrame.

Answer: The two most common strategies for handling missing values
explained in this section are:

 Drop the row having missing values: The dropna() function can be
used to drop an entire row from the DataFrame
 Estimate the missing value: The fillna(num) function can be used to
replace missing value(s) by the value specified in num.
4. What does the head(n) function do in a DataFrame?

Answer: The head(n) function in a dataframe returns the first n rows of the
data frame, which helps to inspect the beginning of the data quickly.

5. What is the role of NumPy in Python programming?

Answer: NumPy is a fundamental library of numerical and


scientific computer in python. It is a general-purpose array-processing
package. In NumPy, handles mathematical computations which involving
arrays and matrices.
6. Explain the use of the isnull() function in Pandas.

Answer: Pandas provide a function is null() to check whether any value is


missing or not in the Data Frame. This function checks all attributes and
returns True in case that attribute has missing values, otherwise returns False.

[Link] the steps to import and export data using Pandas.

Answer: The steps to import and export data using Pandas are:

Importing Data

 Step 1: Use the command “pip install pandas” to install pandas library
 Step 2: Use the command to “import pandas as pd”
 Step 3: Read data from file using “pd.read_csv(“[Link]”)”
 Step 4: Preview the data using “[Link]()”
Exporting Data:

 Step 1: Ensure your DataFrame (df) is ready for export


 Step 2: Use “df.to_csv(“[Link]”, index-False)” to save the
DataFrame as a CSV file.
8. Explain the concept of handling missing values in a DataFrame with
examples.

Answer: Handling missiog values in a DataFrame is important step in data


preprocessing and data cleaning. To handle missing values in python, there
are multiple ways.

 Identifying Missing Values: Pandas provide a function isnull() to check


whether any value is missing or not in the DataFrame. This function
checks all attributes and returns True in case that attribute has missing
values, otherwise returns False.
 Drop Missing Values: Dropping will remove the entire row (object)
having the missing value(s). The dropna() function can be used to drop
an entire row from the DataFrame.
 Estimate the missing value: The fillna(num) function can be used to
replace missing value(s) by the value specified in num. For example,
fillna(0) replaces missing value by 0. Similarly fillna(1) replaces missing
value by 1.

You might also like