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

Assignment07

Uploaded by

yykarkare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment07

Uploaded by

yykarkare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

National Institute of Electronics& Information Technology

Gorakhpur

Day-07:

Q.1 Multiple Choice Question

1. Which one is not true for Pandas Module ?


a. It is free software library for Python.
b. It provides – Series and Dataframe data structures.
c. It does not have graphical capabilities.
d. It enhances the NumPy, Scipy and Matplotlib capabilities.

2. Which one is not true for Pandas Data Structure?


a. Series is a 1-D labeled homogeneous array.
b. Series allows accessing values by index.
c. Dataframe is a 2-D labeled heterogeneous array.
d. Dataframe allows accessing values as index in loc( ).

3. Which one is not true for Series?


a. Series can be created from dataframe.
b. Series can be created from dictionary.
c. Series allows accessing the items using integer index.
d. Series allows accessing the items using label index.

4. Which one is not true for Dataframe?


a. df.pop(‘col’ )- remove the column from the dataframe.
b. del df[‘col’] - can be used to remove the column from the dataframe.
c. Dataframe cannot be created from dictionary of series.
d. Dataframe can be created from List of dictionary.

5. Which is not valid for Dataframe Accessing?


a. df.loc[ ] allows accessing rows based on Boolean index.
b. df.loc[ ] allows accessing rows based on Integer index .
c. df.iloc[ ] allows accessing rows based on Boolean index only.
d. df.iloc[ ] allows accessing rows based on integer index only.

Q.2 What is the output import pandas as pd

df = pd.DataFrame({'X':[78,85,96,80,86], 'Y':[84,94,89,83,86],'Z':[86,97,96,72,83]});
print(df)

Day-14 < Pandas Module>


Page 1 of 6
National Institute of Electronics& Information Technology
Gorakhpur

Ans: X Y Z
0 78 84 86
1 85 94 97
2 96 89 96
3 80 83 72
4 86 86 83

Q.3 Perform the Following Operation on Data Frame

1. Create a dataframe with following data of month 1-6

import pandas as pd

# Step 1: Create a DataFrame for months 1-6

data1 = {

"Month": [1, 2, 3, 4, 5, 6],

"Product": ["Shampoo", "Soap", "Toothpaste", "Lotion", "Shampoo", "Soap"],

"Sales": [150, 200, 250, 180, 220, 240]

df1 = pd.DataFrame(data1)

print("DataFrame for months 1-6:")

print(df1)

Day-14 < Pandas Module>


Page 2 of 6
National Institute of Electronics& Information Technology
Gorakhpur

2. Add the column Total_Sales.

# Step 2: Add Total_Sales column

df1["Total_Sales"] = df1["Sales"]

print("\nDataFrame after adding Total_Sales:")

print(df1)

3. Create a new data frame with data of month 7-11

# Step 3: Create a DataFrame for months 7-11

data2 = {

"Month": [7, 8, 9, 10, 11],

"Product": ["Shampoo", "Soap", "Lotion", "Toothpaste", "Shampoo"],

"Sales": [210, 260, 190, 300, 280]

df2 = pd.DataFrame(data2)

df2["Total_Sales"] = df2["Sales"] # Add Total_Sales for consistency

print("\nDataFrame for months 7-11:")

print(df2)

4. Concatenate this data Frame with the DataFrame created in Step-1

# Step 4: Concatenate the two DataFrames

df_combined = pd.concat([df1, df2], ignore_index=True)

print("\nConcatenated DataFrame:")

print(df_combined)

Day-14 < Pandas Module>


Page 3 of 6
National Institute of Electronics& Information Technology
Gorakhpur
5. Print the sales detail of month -7 and month-8.

# Step 5: Print sales detail of months 7 and 8

sales_7_8 = df_combined[df_combined["Month"].isin([7, 8])]

print("\nSales detail of month 7 and 8:")

print(sales_7_8)

6. Print the sales detail of shampoo.

# Step 6: Print sales detail of Shampoo

shampoo_sales = df_combined[df_combined["Product"] == "Shampoo"]

print("\nSales detail of Shampoo:")

print(shampoo_sales)

7. Print the Total_Sales of all the months.

# Step 7: Print Total_Sales of all months

total_sales = df_combined["Total_Sales"].sum()

print("\nTotal Sales of all months:", total_sales)

Q.4 Find the output based on this data


Sales data of ParleBiscuit( in KG)
Name Jan Feb Mar Apr May Jun
Ajay 10 21 23 31 7 22
Vijay 13 17 12 29 14 16
Sanjay 17 15 16 13 18 10
Ajit 45 21 7 34 22 34
Vikas 22 56 76 34 22 16
Vipul 12 17 22 36 31 23
Rakesh 31 23 27 41 32 22

1. Find the Total Sales of each sales person. [ df.sum(axis=1) ]

df.sum(axis=1)

Day-14 < Pandas Module>


Page 4 of 6
National Institute of Electronics& Information Technology
Gorakhpur

2. Find the Maximum Sales of each sales person [ df.max(axis=1) ]

df.max(axis=1)

3. Show the sales data of “Vikas” for all the months [ df.loc[4 ]) ]

df.loc[4]

4. Show the Sales data of all the sales person for the month of APR. [ df[‘Apr’]] 5.

Show the sales data of FEB and JUN for the entire sales person. [df[ [‘Feb’, ‘Jun’

]]

df['Apr']

6. Show the sales data of “Ajit” for the month of Apr, May, Jun.

[ n=df.loc[ 3]
n[ [‘Apr’,’May’,’Jun’] ] ]
n = df.loc[3]
n[['Apr', 'May', 'Jun']]
7. Find average sales of each sales person. [ df.mean(axis=1) ]

df.mean(axis=1)

8. Find the Minimum sales of each sales person. [ df.min(axis=1) ]

df.min(axis=1)

9. Find the Minimum sales for each month. [ df.min( axis=0) ]

df.min(axis=0)

10. Find the median sales of each sales person. [ df.median(axis=1) ]

df.median(axis=1)

11. Find the median sales for each month. [ df.median(axis=0) ]

df.median(axis=0)

Day-14 < Pandas Module>


Page 5 of 6
National Institute of Electronics& Information Technology
Gorakhpur
import pandas as pd
df=pd.read_csv("d:\\pyprg\\salesdata.csv") print(df)

Day-14 < Pandas Module>


Page 6 of 6

You might also like