Informatics Practices
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 :
Name | Department | Salary | |
---|---|---|---|
0 | Divya | HR | 95000 |
1 | Mamta | Marketing | 97000 |
2 | Payal | IT | 980000 |
3 | Deepak | Sales | 79000 |
Python Pandas
5 Likes
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
Answered By
3 Likes
Related Questions
If Ser is a Series type object having 30 values, then how are statements (a), (b) and (c), (d) similar and different ?
(a) print(Ser.head())
(b) print(Ser.head(8))
(c) print(Ser.tail())
(d) print(Ser.tail(11))
What advantages does dataframe offer over series data structure ? If you have similar data stored in multiple series and a single dataframe, which one would you prefer and why ?
Carefully observe the following code :
import pandas as pd Year1 = {'Q1': 5000, 'Q2': 8000, 'Q3': 12000, 'Q4': 18000} Year2 = {'A': 13000, 'B': 14000, 'C': 12000} totSales = {1: Year1, 2: Year2} df = pd.DataFrame(totSales) print(df)
Answer the following :
(i) List the index of the DataFrame df.
(ii) List the column names of DataFrame df.
Given :
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']) print(df) print(df1) print(df2)
What will Python show the result as if you execute above code ?