CBSERanker

Loading

Worksheet Dataframe

Worksheet Dataframe

Q1. What is a DataFrame?


Q2. Write code to create an empty DataFrame named ‘DF1’.


Q3. Which method is used to create a DataFrame in Python?


Q4. Write two differences between Series and DataFrame.


Q5. Create the following DataFrame using a list of dictionaries.

ABC
123
568

Q6. Which data types can be used to create a DataFrame?


Q7. Which library is imported to create DataFrame from NumPy arrays?


Q8. _______ method in Pandas is used to change/modify the index of rows and columns of a DataFrame.


Q9. Give an example to create a DataFrame from a single ndarray.


Q10. Give an example to create a DataFrame from two ndarrays.


Q11. Write the output of the following code:

pythonCopy codeimport numpy as np
import pandas as pd
A = np.array([35, 40, 71, 25])
B = np.array([27, 34, 56, 73])
C = [11, 22, 33, 44]
DF = pd.DataFrame([A, B, C])
print(DF)

Q12. Write the Python code to create a DataFrame from the given list:

pythonCopy codeL1 = ["Anil", "Ruby", "Raman", "Suman"]
L2 = [35, 56, 48, 85]

Q13. Fill in the blank to produce the following output:

pythonCopy codeimport pandas as pd
L1 = ["Anil", "Ruby", "Raman", "Suman"]
L2 = [35, 56, 48, 85]
DF = pd.DataFrame([L1, L2], ___________________________________ )
print(DF)

Output:

IstIIndIIIrdIVth
AnilRubyRamanSuman
35564885

Q14. Aman stores data in the form of a nested list. He creates a DataFrame ‘DF’ from the list using the following code. How many columns are there in “DF”?

pythonCopy codeL1 = [["Aman", "Cricket", "7th"], ["Ankit", "Hockey", "11th"], ["Sunita", "Basketball", "9th"]]
import pandas as pd
DF = pd.DataFrame(L1)
print(DF)

Q15. Which attribute of DataFrame is used to set a user-defined index?


Q16. Which attribute of DataFrame is used to set a user-defined column name?


Q17. Complete the following code to get the output shown below:

pythonCopy codeimport pandas as ________________
L1 = [["Aman", 45], ["Ankit", 56], ["__________", 67]]
DF = pd.______________(L1, ______________=["Name", "Marks"], index=[__________])
print(DF)

Output:

NameMarks
Aman45
Ankit56
Sunita67

Q18. Complete the following code to get the output shown below:

pythonCopy codeimport pandas as pd
L1 = {"Name" : ["Aman", "Ankit", "Sunita"], "Marks" : [45, 56, 67]}
DF = pd.DataFrame(L1, columns=[____________________], index=[1, 2, 3])
print(DF)

Output:

MarksName
45Aman
56Ankit
67Sunita

Q19. Consider the code below and answer the questions:

pythonCopy codeLd = [{'a' : 10, 'b' : 20}, {'a' : 5, 'b' : 10, 'c' : 20}]
DF = pd.DataFrame(Ld)
print(DF)

a. How many rows are in the DataFrame “DF”?
b. How many columns are in the DataFrame “DF”?
c. How many NaN values are in the DataFrame “DF”?
d. Write the missing import statement in the code.
e. How many dictionaries are used in the code?


Q20. Give an example of creating a DataFrame from two Series.

Leave a Reply

Your email address will not be published. Required fields are marked *