WorksheetsPandas Dataframe and Series
Total questions: 40
Worksheet time: 24mins
Pandas deals with following data structures
Series
Series and Data Frames
Series, DataFrames and Panel
None of Above
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()
Dataframe can contain multiple series
True
False
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 of the following can be used to make a Dataframe?
Series
DataFrame
Structured ndarray
All of the above
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
Type the syntax that returns the top 5 rows in DataFrame df with the native Pandas function (not slicing):
(a)
Among the following functions, which one can be used to combine dataframes when they have similar structure.
combine_first
concat()
merge()
For the concat(), if the axis=1, it will join the dataframes ...............
vertically
horizontally
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()
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
Which is true for series.
Size is mutable,Values is mutable
size is immutable,values is mutable
size is mutable,values is immutable.
none
To extract subset from Series,the following function is used
row()
column()
loc()
all
Minimum number of argument we require to pass in pandas series ?
0
1
2
3
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
Which of the functions can be used to delete column/row from a DataFrame?
pop()
at()
drop()
iloc()
Full form of CSV file is
Comma Separated Vault
Comma Separated Value
Common Separated Value
Common System Value
1. Given the following Series A1 and A2: 1
A1 A2
a 20 a 70
b 10 b 30
c 24 c 84
d 70 d 80
Write the command to find the sum of series A1 and A2
A1+A2
sum(A1,A2)
a1+a2
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 know the age of the persons with rank3. Help her to identify the correct set of statement/s from the given options:
a) Print(df.loc[‘rank3’])
b) print(df.iloc[‘rank3’])
c) print(df.loc[‘rank3’])
d) Print(df.loc(‘rank3’))
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
The instructor wants to add a new row to the dataframe. Help him to choose the correct command to do so.
df.loc[]
df.iloc[]
PANDAS stands for _________________
Panel Data Analyst
Panel Data Analyse
Panel Data
Panel Database
To display third element of a Series object S, you will write
S[:3]
S[02]
S[2]
S[:2]
To display the 3rd, 4th and 5th columns from the 6th to 9th rows of a dataframe you can write
DF.LOC[6:9, 3:5]
DF.LOC[6:10, 3:6]
DF.iloc[6:10, 3:6]
DF.iloc[6:9, 3:5]
What will be the output for the following code ?
>>> import pandas as pd
>>> S = pd. Series([1,2,3,4,5],index = ['a', 'b', 'c', 'd', 'e'])
>>> print ( s[ 'a'] )
2
1
3
4
