English

Carefully observe the following code: import pandas as pd dic={'pid': [101, 102, 103, 104, 105], 'pname': ['shyam', 'Roushan', 'Archit', 'Medha', 'Lalit'], 'sports':

Advertisements

Question

Carefully observe the following code:

import pandas as pd 
dic={'pid': [101, 102, 103, 104, 105], 
'pname': ['Shyam', 'Roushan', 'Archit', 'Medha', 'Lalit'], 
'sports': ['Cricket', 'Tennis', 'Football', 'Cricket', 'Cricket'], 
'points': [45000, 20000, 15000, 53000, 60000]} 
player=pd.Data Frame(dic)
print(player)

Write Python statements for the following:

  1. In the dataframe player created above, set the row labels as 'Player 1', 'Player 2', 'Player 3', 'Player 4', 'Player 5'.
  2. Rename the column 'points' to 'netpoint' in the DataFrame player.
Code Writing
Advertisements

Solution

  1. player.index=['player1','player2','player3','player4','player5'] 
  2. player.rename(columns={'points':'netpoint'})
shaalaa.com
  Is there an error in this question or solution?
2022-2023 (March) Set 4
Advertisements
Share
Notifications



      Forgot password?
Use app×