In: Computer Science
Type the Python code for all the questions. 1 2 Q1: Using DataFrame, with Figure 1 data, store the hypermarket data for rows and columns. Display the output as shown in Figure 1. 0 ITEMS NAME DISCOUNT 1 Grocery Rice 56 2 Electronics Mobile 25% 3 Food Apple 30% Figure 1 Q2: Update and display the "Rice" discount from 5% to 10%. Your output should be like Figure 2 now. 1 2 0 ITEMS NAME DISCOUNT 1 Grocery Rice 108 2 Electronics Mobile 25% 3 Food Apple 30% Figure 2 NO Q3: Use Figure 3 data to add and display a new column. Your output should be like Figure 3 now. 0 1 2 3 ITEMS NAME DISCOUNT STOCK Grocery Rice 10% 100 Electronics Mobile 25% 3 Food Apple 30% W NO 20 40 Figure 3
CODE:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
data = [['Grocery', 'Rice', '5%'], ['Electronics', 'Mobile',
'25%'],
['Food', 'Apple', '30%']]
df = pd.DataFrame(data, columns = ['ITEMS', 'NAME',
'DISCOUNT'])
# print dataframe.
print(df)
df.loc[df['NAME'] == 'Rice', 'DISCOUNT']='10%'
print(df)
stock=[100,3,20]
df['STOCK']=stock
print(df)
OUTPUT:
If you have any doubts please COMMENT....
If you understand the answer please give THUMBS UP....