Data Frame Qp_1

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Suma
S
Suma
Community Contributor
Quizzes Created: 4 | Total Attempts: 7,237
| Attempts: 1,341 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. What will be the output of the following code? import pandas as pd import numpy as np arr1=np.array([[1,2,3],[4,5,6]]) df=pd.DataFrame(arr1,columns=['num1','num2','num3']) print(df.iloc[0,2])

Explanation

The code imports the pandas and numpy libraries. It creates a NumPy array called arr1 with two rows and three columns. Then, it creates a DataFrame called df using the arr1 array and assigns column names 'num1', 'num2', and 'num3' to the DataFrame. Finally, it prints the value at the first row and third column of the DataFrame, which is 3.

Submit
Please wait...
About This Quiz
Data Frame Qp_1 - Quiz

Data Frame QP_1 quiz assesses knowledge in manipulating data using Python's Pandas library. It covers DataFrame creation, data manipulation, and indexing, providing practical Python coding insights useful for... see moredata science applications. see less

2. A dictionary grade contains the following Grade={'Name':['Rashmi','Harsh','Ganesh','Priya','Vivek'],'Grade':['A1','A2','B1','A1','B2']} Write the statement to add a column called 'Marks' with the following data. [97,92,95,89,96] use only single quotes in the answer as the software gives correct only for exact match

Explanation

The statement "Gr['Marks']=[97,92,95,89,96]" adds a column called 'Marks' to the dictionary grade and assigns the values [97,92,95,89,96] to it.

Submit
3. Delete 3rd and 5th rows Hint use drop method in a single statement

Explanation

The given code is using the "drop" method to delete the 3rd and 5th rows from the DataFrame "Gr". The drop method is being passed a list of indices [2,4] which corresponds to the 3rd and 5th rows. By calling the drop method on "Gr" with the specified indices, those rows are deleted from the DataFrame.

Submit
4. In Pandas, the method used to create a DataFrame from a dictionary is __________.

Explanation

In Pandas, pd.DataFrame is the method used to create a DataFrame from various data structures like dictionaries, lists, or arrays. A DataFrame is a two-dimensional, labeled data structure with columns that can hold different data types. It is one of the most commonly used data structures in Pandas, allowing for easy manipulation, analysis, and visualization of data.

Submit
5. Import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),    'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) df1=pd.DataFrame(d,index=['d','b','a']) df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) Write code to display only column one for rows b and c from df 

Explanation

The code `print(df.loc['b':'c','one'])` is used to display only the values in column 'one' for the rows with index 'b' and 'c' from the DataFrame `df`. The `loc` function is used to access specific rows and columns based on their labels. In this case, the code selects rows 'b' to 'c' (inclusive) and column 'one' from the DataFrame `df` and prints the corresponding values.

Submit
6. Give the output import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),   'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) print(df) Hint.  only one space between columns and rows and start from the left and  and leave one space from top margin

Explanation

The given code imports the pandas library and creates a dictionary 'd' with two keys 'one' and 'two'. Each key has a corresponding pandas Series as its value. The Series contain numerical values with specified indices. The code then creates a pandas DataFrame 'df' using the dictionary 'd'. Finally, it prints the DataFrame 'df'. The output shows the DataFrame with two columns 'one' and 'two', and the corresponding values from the Series. The indices are displayed on the left side.

Submit
7. Give the output import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),   'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df1=pd.DataFrame(d,index=['d','b','a']) print(df1) Hint.  only one space between columns and rows and start from the left and top margin

Explanation

The code creates a DataFrame using the given dictionary 'd' and sets the index of the DataFrame to ['d','b','a']. The DataFrame has two columns, 'one' and 'two', which correspond to the values in the dictionary. The output shows the DataFrame with the specified index and the corresponding values from the dictionary.

Submit
8.   import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),   'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) print(df2)

Explanation

The given code creates a DataFrame 'df2' using the dictionary 'd' with specified index and columns. The DataFrame has two columns 'two' and 'three'. However, since 'three' is not present in the dictionary 'd', the values for 'three' column are NaN (Not a Number). The values for 'two' column are 4.0 and 1.0 for index 'd' and 'a' respectively.

Submit
9. Import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),    'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) df1=pd.DataFrame(d,index=['d','b','a']) df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) Write code to  Display only column 'one' from dataframes df and df1, column 'two' from  df2. Hint: Write print statements one below the other

Explanation

The code is using print statements to display specific columns from the dataframes df, df1, and df2. It first prints the column 'one' from df, then the column 'one' from df1, and finally the column 'two' from df2.

Submit
10. Import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),    'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) df1=pd.DataFrame(d,index=['d','b','a']) df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) Write code to display only rows 0 and 1 from dataframes df, df1  and df2 Hint :use iloc use print statements one below the other  

Explanation

The code is displaying only rows 0 and 1 from dataframes df, df1, and df2 using the iloc function. The iloc function is used to select rows and columns by their integer position. In this case, [0:2,] is used to select rows 0 and 1. The print statements are used to display the selected rows for each dataframe.

Submit
View My Results

Quiz Review Timeline (Updated): Aug 14, 2024 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Aug 14, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 30, 2020
    Quiz Created by
    Suma
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will be the output of the following code? ...
A dictionary grade contains the following ...
Delete 3rd and 5th rows Hint use drop method in a single statement
In Pandas, the method used to create a DataFrame from a dictionary is...
Import pandas as pd ...
Give the output ...
Give the output ...
  import pandas as pd ...
Import pandas as pd ...
Import pandas as pd ...
Alert!

Advertisement