DataFrame Revision
DataFrame Revision
2) Consider the code given below and answer the following question:
Ld=[{'a',10,'b':20},{'a':5,'b':10,'c':20}]
df=pd.DataFrame(Ld)
print(df)
i) Write the missing statement in the above code which will give error.
ii) How many columns will be there in the dataframe.
for the year 2010 to 2012 for January, March and December. His
manager wants certain information from him, but he is facing some
problems. Help him by answering few questions given below:
10) The python code written below has syntactical errors. Rewrite the
correct code
and underline the corrections made.
IMPORT pandas as pd
df ={"name":["satish","rahul","arvind"],"exp(in months)":[14,41,31]}
df= pd.dataframe(df)
print(df)
11) Write a Python code to create a DataFrame with column headings
as (stu_id, name, class) and data labels as (1,4,5,6) from the list given
below:
L1=[[101,'Guru',10],[102,'Raj',9],[103,'Sam',12],[104,'Yuvraj',12]]
13) Consider the following DataFrame, Class DF with row index St1, St2,
St3, St4
14) The python code written below has syntactical errors. Rewrite the
correct code
and underline the corrections made.
import pandas as pt
data = {'Name': ['Ramesh Pillai', 'Priya Nair', 'Suresh Menon'], 'Age':
[28, 32, 26],
'City': ['Mcleodganj', 'Jalandhar', 'Sanchor']}
df = pd.DataFrame(data)
print(df.head)
15) You are tasked with creating a DataFrame to store information about
gaming apps available on various digital platforms. The DataFrame
should have three columns: Name, Genre, Type (Free or Paid), and
Downloads. To achieve this, you have the following data:
Page 5 of 7
Now create a dataframe with a dictionary of Series and index should be from
1 to 5.
17) Riya, a Data Analyst working for a film studio, has created a
DataFrame named 'movie_revenue_df' to store the revenue data of
movies released by Viacom 18 in the year 2022. The DataFrame looks
like this:
Movie Revenue (in crores)
A. Gangubai Kathiawadi 125
B. The Kashmir Files 340
C. Bhediya 75
D. JugJugg Jiyo 250
E. Bachchhan Pandey 120
An intern is working with her and has a few doubts. As Riya is busy with
analysis work. You answer on her behalf.
(i) Predict the output of the following python statement:
a. print(movie_revenue_df[‘Revenue (in crores)’].dtypes)
b. print(movie_revenue_df.iloc[2,0])
Page 6 of 7
18) Answer the following questions based on the code given below : -
…………………….... # Statement 1
Ld=[{'a',10,'b':20},{'a':5,'b':10,'c':20}]
df=pd.DataFrame(Ld)
print(df)
i) Write the statement 1 in the above code.
ii) How many columns will be there in the dataframe.
==========