KnowledgeBoat Logo
|

Informatics Practices

What is the output of the following code ?

data = {'age': [20, 23, 22], 'name': ['Ruhi', 'Ali', 'Sam']} 
df1 = pd.DataFrame(data, index=[1, 2, 3])
print("Before")
print(df1)
df1['Edu'] = ['BA', 'BE' , 'MBA']
print('After')
print(dfl)

Python Pandas

2 Likes

Answer

Before
   age  name
1   20  Ruhi
2   23   Ali
3   22   Sam
After
   age  name  Edu
1   20  Ruhi   BA
2   23   Ali   BE
3   22   Sam  MBA

Working

The code utilizes the pandas library in Python to create a DataFrame named df1 using a dictionary data. The df1 DataFrame is printed, showing the initial data. Then, a new column 'Edu' is added to the DataFrame using df1['Edu'] = ['BA', 'BE' , 'MBA']. The updated DataFrame is printed.

Answered By

3 Likes


Related Questions