Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1. Perform at least two operations using both .loc[] and .

iloc[] functions on the data


frame given below:
Col1 Col2 Col3 Col4 Col5
Row1 1 2 3 4 5
Row2 3 4 5 6 7
Row3 5 6 7 8 9
Row4 3 4 5 6 7
Row5 5 6 7 8 9
2. Set weekdays as an index for the data frame given below:

city sells visitors weekdays


0 Blr 22 255 Sun
1 Del 5 25 Mon
2 Hyd 25 300 Sat
3 Pune 30 455 Sat

3. Drop an index i.e Row3 from data_frame given in question 2, and reset the index
using .reset_index() function.

4. Execute the following command on the data frame given in question number 2
and explain what happens.

df.reset_index().drop_duplicates(subset='index', keep='last').set_index('index')

5. Create a data frame using the given dictionary and remove the rows having
missing values(nan), not more than 2. And reset the index of the data frame.

d={'A':[1,2,np.NaN,5,8,12],
'B':[1,np.NaN,np.NaN,24,12,34],'C':[1,2,3,11,np.nan,17]}

6. Create a data frame using the given function and find unique values and the
number of occurrences of every value in the df.

{"col1":[1,2,3,4],'col2':[444,333,111,444,],'col3':['abc','def','ghi',"xyz"]}

7. Create a data frame from the dictionary given below and perform the given
operations using .groupby() function of pandas.

{"Company": [ "CompA", "CompA", "CompB", "CompB", "CompC", "CompC"],


"Person": ["Rajesh", "Pradeep", "Amit", "Rakesh", "Suresh", "Raj"],
"Sales": [200, 120, 340, 124, 243, 350]}
Operations:
A. group data by ‘company’ label
B. apply standard deviation on grouped data by ‘company’ label
C. Sum the sales of the same companies and fetch the data, use .groupby()
function.

You might also like