WorksheetsPython Pandas 1 by RK
Total questions: 62
Worksheet time: 31mins
Best way to import the pandas module in your program ?
1.import pandas
2.import pandas as pd
3.from pandas import *
4.All of the above
DataFrame in pandas is
1. dimensional array
2. dimensional array
3.dimensional array
4.None of the above
All pandas data structures are ___ mutable but not always _______mutable.
a) size, value
b) semantic, size
c) value, size
d) none of the mentioned
Which of the following object you get after reading CSV file?
a) DataFrame
b) Character Vector
c) Panel
d) All of the mentioned
Which of the following library is similar to Pandas?
a) NumPy
b) RPy
c) SciPy
d) None of the mentioned
Which is not a feature of series
Homogeneous data
Immutable size
Mutable data
Multiple rows
Series can be created from
Array
Dictionary
Scaler value
All of them
Full form of CSV file is
Comma Separated Vault
Comma Separated Value
Common Separated Value
Common System Value
Not a function of Dataframe
Head()
Tail()
loc()
multi()
Which function from the options given below can read the dataset from a large text file?
read_json
read_pickle
read_hdf
read_csv
Which is the correct Pandas syntax to read in a csv file and assign it to a DataFrame df?
df = read_csv('file.csv')
df = read('file.csv', type = 'csv')
df = pd.read_csv('file.csv')
df = with open('file.csv') as pd.DataFrame
Among the following functions, which one can be used to combine dataframes when they have similar structure.
combine_first
concat()
merge()
Which function can be used to combine dataframes based on common fields?
merge()
combine_first()
concat()
Which function views dataframe in the form of vertical subset ie column wise?
iterrows()
iteritems()
Which of the functions can be used to delete column/row from a DataFrame?
pop()
at()
drop()
iloc()
Series.tail(3) will return how many values.
3 values from front
3 values from last
5 values
none
To extract subset from Series,the following function is used
row()
column()
loc()
all
we can analyze the data in pandas with :
Series
Dataframe
Both
none
Series in Pandas is
1 Dimensional Array
2 Dimensional array
3 Dimensional array
none of above
Which package should be needed for series
Maths
Statistic
Pandas
Random
Full form of NaN is
Not a Null
Not a Number
Not a Numeric
None of these
pandas is a:
Data Structure
Series
Dataframe
Library
Write the output for the following:
import pandas as pd1
s = pd1.Series(5, index=[0, 1, 2, 3])
print(s)
0 5
0 5
1 5
2 5
3 5
dtype: int64
1 5
2 5
2 5
4 5
dtype: int64
0 5
1 5
2 5
3 5
dtype: object
write the output:
import pandas as pd1
s = pd1.Series([1,2,3])
t = pd1.Series([1,2,4])
u=s-t
print (u)
0 1
1 0
2 1
dtype: int64
0 0
1 0
2 1
dtype: int64
0 0
1 0
2 -1
dtype: float64
0 0
1 0
2 -1
dtype: int64
write the output:
import pandas as pd
s=pd.Series([1,2,3,4],index=['a','b','c','d'])
print(s.iloc[2:4])
b 2
c 3
d 4
dtype: int64
b 3
c 4
dtype: int64
c 3
d 4
dtype: int64
none of the above
write the output:
import pandas as pd
s=pd.Series([1,2,3,4],index=['a','b','c','d'])
print(s.loc['b':'d'])
b 2
c 3
d 4
dtype: float64
b 2
c 3
d 4
dtype: object
c 3
d 4
dtype: int64
b 2
c 3
d 4
dtype: int64
Give the output of the following code:
>>>import pandas as pd
>>>dict1 = {'AR' : 100, 'VR' : 200, 'AI' : 300}
>>>ser = pd.Series(dict1)
>>>print(ser[1])
AR
100
VR
200
print(ser[2,4])
print(ser[[2:4]])
print(ser[[2,4]])
print(ser[2,3,4])
print(ser[[1,3]])
print(ser[1:3])
print(ser[[1:3]])
print(ser[1,3])
What will be the print statement to display the elements of a series series1 from end till beginning in step 2?
print(series1[::-2])
print(series1[::2])
print(series1[:-2:])
print(series1[:2:])
pd.DataFrame(DICT1, columns=["NAME","DOB"])
pd.DataFrame(DICT1, index=["NAME","DOB"])
pd.DataFrame(DICT1, index=["NAME":"DOB"])
pd.DataFrame(DICT1, columns=["NAME":"DOB"])
print(pd.DataFrame(DICT1, index=[1,2,3], columns=["NAME","SCODE"]))
print(pd.DataFrame(DICT1, index=[501,502,503], columns=["NAME","SCODE"]))
print(pd.DataFrame(DICT1, index=[501,502,503], columns=["NAME":"SCODE"]))
print(pd.DataFrame(DICT1, index=[501:503], columns=["NAME","SCODE"]))
DICT1.drop(504, axis=0)
DICT1.drop(4, axis=0)
DICT1.drop(504, axis=1)
DICT1.drop(4, axis=1)
DICT1[4]>=500
DICT1["SCORE"]>=500
DICT1["SCORE"]<=500
DICT1["SCORE">=500]
DICT1.loc[502:505]
DICT1.loc[:,502:505]
DICT1.iloc[1:5]
DICT1.iloc[1:4]
Basic feature of DataFrame are
homogenous data with mutable size
hetrogenous data with mutable size and values
homogeous data single dimensional
Pandas deals with following data structures
Series
Series and Data Frames
Series, DataFrames and Panel
None of Above
Series.head() will return how many rows.
2
3
4
5
What does this line of code do?
Returns unique values
Checks duplicates
Drops duplicates
Checks index duplicates
Minimum number of argument we require to pass in pandas series ?
0
1
2
3
Which function needs a dictionary of array like sequences or a dictionary of another dictionary, to return a DataFrame?
DataFrame.from_items
DataFrame.from_records
DataFrame.from_dict
All of the above
To get the number of dimensions of a Series object, ____________ attribute is displayed
itemsize
size
index
ndim
To check if the Series object contains NAN values, _____________ attribute is displayed.
hasnans
nbytes
ndim
dtype
To get the number of bytes of the Series Data, ___________________ attribute is used.
index
size
itemsize
ndim
While we concat, if we do not want the mechanism for row indexes and want to have new row indexes generated from 0 to n-1, then we can give argument ignore_index as .............
False
True
The axis 0 identifies a dataframe's ..............
rows
columns
values
datatype
To extract row/column from a dataframe, ............. function may be used.
row()
column()
loc()
All of these
The axis 1 identifies a dataframe's ...............
rows
columns
values
datatype
To delete a column from a DataFrame, you may use ............ statement.
remove
del
drop
pop
Ms.Sharma, the class teacher wants to add a new column, the scores of Grade with the values, 'A','B','A','A', to the DataFrame. Help her choose the command to do so:
df.column=[ 'A','B','A','A']
df ['Grade']=[ 'A','B','A','A']
df . loc ['Grade']=[ 'A','B','A','A']
Which among the following is correct to display the column Hospitals from the above dataframe?
print(dtf5 [ Hospitals ])
print(dtf5 . Hospitals )
pring(dtf5 [ 'Hospitals' ])
print(dtf5 { Hospitals })
Among the following which all statements can be used to display the details of Kolkata.
print( dtf5.iloc[2, : ])
print( dtf5.iloc[ 'Kolkata' ])
print( dtf5.loc[ 'Kolkata' ])
print( dtf5.iat[ 'Kolkata' ])
Which of the following commands is used to convert array named "grades" into data frame named "df_grades"?
df_grades = grades
df_grades = pd.DataFrame(grades)
df_grades = pd.DataFrame("grades")
grades = pd.DataFrame(df_grades)
Among the following which all statements can be used to delete the row having index 'Chennai'?
dtf5=dtf5.drop('Chennai')
dtf5.drop('Chennai',axis=0,inplace=True)
dtf5=dtf5.drop('Chennai',axis=1)
dtf5=dtf5.drop(index='Chennai')
The __________ attribute of a dataframe object returns the row labels of a dataframe.
columns
Columns
Index.Values
index.values
DataFramedf
Age Name
rank1 28 Tom
rank2 34 Jack
rank3 29 Steve
rank4 42 Ricky
Find out the command used to get the following output from the above dataframe,
Age
rank1 28
rank2 34
rank3 29
rank4 42
Print(df[‘Age’])
print(df[‘Age’])
print(df(‘Age’))
Print(df[‘Age’], axis=1)
The instructor wants to add a new column, Marks to the dataframe. The values of the marks will be 12, 22, 21, 24. Help him to choose the correct command to do so.
a) Df.columns=[12, 22, 21, 24]
b) df[‘marks’] = [12, 22, 21, 24]
c) df.loc[marks] = [12, 22, 21, 24]
d) Both (b) and (c) are correct
For the given DataFrame df, what will be the code to get the value 38?
df . iloc [1,1]
df . Age [222]
df . loc [111]
None of the above
Way to install the pandas library ?
pip install pandas
PIp install pandas
To display third element of a Series object S you will write___
S [ : 3 ]
S [ 2 ]
S [ 3 ]
S [ : 2 ]
_________ function is used to access individual values
it ()
bit ()
at ()
set ()
The insert function requires ____ number of arguments in DataFrame.
1
2
3
4
