Page 80 - IPP-12-2024
P. 80
1 a
2 b
dtype: object
3 c
dtype: object
a
According to Condition
Series([], dtype: object)
Program 11. Write a Program to enter data and show data in python using DataFrames and pandas.
Solution:
import pandas as pd
data = [['Rajiv',10],['Sameer',12],['Kapil',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
print (df)
data1 = {'Name':['Rajiv', 'Sameer', 'Kapil',
'Nischay'],'Age':[28,34,29,42],
'Designation':['Accountant','Cashier','Clerk','Manager']}
df1 = pd.DataFrame(data1)
print (df1)
Output:
Name Age
0 Rajiv 10
1 Sameer 12
2 Kapil 13
Name Age Designation
0 Rajiv 28 Accountant
1 Sameer 34 Cashier
2 Kapil 29 Clerk
3 Nischay 42 Manager
Program 12. Write a Program to enter multiple values-based data in multiple columns/rows and
show that data in python using DataFrames and pandas.
Solution:
import pandas as pd
weather_data= {
'day':
['01/01/2018','01/02/2018','01/03/2018','01/04/2018','01/05/2018','01/0
1/2018'],
'temperature': [42,41,43,42,41,40],
'windspeed': [6,7,2,4,7,2],
'event': ['Sunny','Rain','Sunny','Sunny','Rain','Sunny']
}
df=pd.DataFrame(weather_data)
print(df)
print("Number of Rows and Columns")