CBSE Class 12 Informatics Practices Question 29 of 40

Practice Paper — Question 3

Back to all questions
3
Question

Question 27

Create a DataFrame in Python from the given list :

[['Divya', 'HR', 95000], ['Mamta', 'Marketing' ,97000],
['Payal', 'IT', 98000], ['Deepak', 'Sales', 7900]]

Also give appropriate column headings as shown below :

 NameDepartmentSalary
0DivyaHR95000
1MamtaMarketing97000
3PayalIT980000
4DeepakSales79000
Answer
import pandas as pd
data = [['Divya', 'HR', 95000], ['Mamta', 'Marketing', 97000], ['Payal', 'IT', 980000], ['Deepak', 'Sales', 79000]]
df = pd.DataFrame(data, columns=['Name', 'Department', 'Salary'])
print(df)
Output
    Name Department  Salary
0   Divya         HR   95000
1   Mamta  Marketing   97000
2   Payal         IT  980000
3  Deepak      Sales   79000