0% found this document useful (0 votes)
13 views

Document (4)-1

The document outlines various operations using pandas, including creating Series and DataFrames, filtering data, calculating statistics, and handling missing values. It provides examples of outputs for tasks such as grouping data, merging DataFrames, and manipulating date and time data. Each section demonstrates specific functionalities of pandas with corresponding outputs for clarity.

Uploaded by

lalitlalit98697
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)
13 views

Document (4)-1

The document outlines various operations using pandas, including creating Series and DataFrames, filtering data, calculating statistics, and handling missing values. It provides examples of outputs for tasks such as grouping data, merging DataFrames, and manipulating date and time data. Each section demonstrates specific functionalities of pandas with corresponding outputs for clarity.

Uploaded by

lalitlalit98697
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
You are on page 1/ 15

#1. Create a pandas series from a dictionary of values and an ndarray.

Output:-

0 9
1 8
2 7
3 6
4 5
5 4
6 3
dtype: int64

Output:-

A 500
B 1000
C 1500
dtype: int64
#2 Given a Series, print all the elements that are above the 75th
percentile.

Output:-

0 1
1 3
2 4
3 7
4 8
5 8
6 9
dtype: int64

75th Percentile of the series is:::


8.0

The elements that are above the 75 th percentile::


6 9
dtype: int64
#3 Create a Data Frame quarterly sales where each row contains the item
Category, item name, and expenditure. Group the rows by the category and
print the total expenditure per category.

Output:-

Original DataFrame:
Category Item Name Expenditure
0 Electronics Laptop 1000
1 Fashion Shirt 50
2 Electronics Tablet 500
3 Fashion Shoes 100
4 HomeGoods Chair 200

Total Expenditure per Category:


Category
Electronics 1500
Fashion 150
HomeGoods 200
Name: Expenditure, dtype: int64
#4. Create a data frame based on ecommerce data and generate descriptive
statistics (mean, median, mode, quartile, and variance).

Output:-

Count 7.00
Mean 18450.00
Std 28543.61
Min 500.00
25% 1575.00
50% 2500.00
75% 29000.00
Max 65000.00
Name: Price, dtype: float64
#5. Create a data frame for examination result and display row labels, column
labels data types of each column and the dimensions.

Output:-

Class Pass-Percentage
0 I 100.0
1 II 100.0
2 III 100.0
3 IV 100.0
4 V 100.0
5 VI 100.0
6 VII 100.0
7 VIII 100.0
8 IX 100.0
9 X 98.6
10 XI 100.0
11 XII 99.0
Class object
Pass-Percentage float64
dtype: object
Shape of the dataframe is:::::
(12, 2)
#6. Filter out rows based on different criteria such as duplicate rows.

Output:-

Name MarksinIP
0 Rohit 85
2 Deepak 92
3 Rohit 85
4 Deepak 92
#7. Find the sum of each column, or find the column with the lowest mean.

Output:-

TCS WIPRO L&T


Qtr1 2500 2800 2100
Qtr2 2000 2400 5700
Qtr3 3000 3600 35000
Qtr4 2000 2400 2100

Column wise sum in datframe is :::


TCS 9500
WIPRO 11200
L&T 44900
dtype: int64

Column wise mean value are:::::::::


TCS 2375.0
WIPRO 2800.0
L&T 11225.0
dtype: float64

Column with minimum mean value is::::::::::::


#8. Locate the 3 largest values in a data frame.

Output:-

Name MarksinIP
4 Pankaj 98
5 Sohit 96
2 Deepak 92
#9. Subtract the mean of a row from each element of the row in a Data Frame.

Output:-

TCS WIPRO L&T


Qtr1 2500 2800 2100
Qtr2 2000 2400 5700
Qtr3 3000 3600 35000
Qtr4 2000 2400 2100

Mean of each row is:::::::::


Qtr1 2466.666667
Qtr2 3366.666667
Qtr3 13866.666667
Qtr4 2166.666667
dtype: float64

Dataframe after Subtracting mean value of each row is :::


TCS WIPRO L&T
Qtr1 33.333333 333.333333 -366.666667
Qtr2 -1366.666667 -966.666667 2333.333333
Qtr3 -10866.666667 -10266.666667 21133.333333
Qtr4 -166.666667 233.333333 -66.666667
#10. Replace all negative values in a data frame with a 0.

Output:-

Data1 Data2
0 -5 2
1 -2 4
2 5 10
3 8 15
4 9 -5
5 -6 -8

dataFrame after replacing negative values with 0:::


Data1 Data2
0 0 2
1 0 4
2 5 10
3 8 15
4 9 0
5 0 0
#11. Replace all missing values in a data frame with a 999.

Output:-

Empid ename Doj


0 101 Sachin 12-01-2012
1 102 Vinod 15-01-2012
2 103 Lakhbir 05-09-2007
3 104 NaN 17-01-2012
4 105 Devinder NaN
5 106 UmaSelvi 16-01-2012

Empid ename Doj


0 101 Sachin 12-01-2012
1 102 Vinod 15-01-2012
2 103 Lakhbir 05-09-2007
3 104 999 17-01-2012
4 105 Devinder 999
5 106 UmaSelvi 16-01-2012
#12. Importing and exporting data between pandas and CSV file

Output:
Name Age
0 John 25
1 Mary 31
#13 HANDLING DATE AND TIME DATA USING PANDAS.

Output:-

Data with DateTime index:

Date sales
2024-01-01 200
2024-02-01 250
2024-03-01 300
#15 MERGING TWO PROVIDED DATAFRAMES IN A SINGLE DATAFRAME USING
PANDAS.

Output:-

Merged DataFrame:
ID Name Salary
0 1 Alice 50000
1 2 Bob 60000
2 3 Charlie 45000
#14 GROUPING THE PROVIDED DATA USING PANDAS.

Output:-

Average Salary by Department:


Department
Finance 75000
HR 47500
IT 67500
Name: Salary, dtype: int64

You might also like