CBSE Class 12 Informatics Practices Question 125 of 167

Python Pandas — I — Question 15

Back to all questions
15
Question

Question 12

Create a DataFrame in Python from the given list :

[['Divya', 'HR', 95000], ['Mamta', 'Marketing', 97000], ['Payal', 'IT', 980000], ['Deepak', 'Sales', 79000]]

Also give appropriate column headings as shown below :

 NameDepartmentSalary
0DivyaHR95000
1MamtaMarketing97000
2PayalIT980000
3DeepakSales79000
Solution
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
Answer