Computer scienceData scienceInstrumentsPandasStoring data with pandas

Accessing data in a DataFrame

Renaming columns

Report a typo

You are working with a DataFrame df_rock that contains sonar signals from two object classes: rocks and mines. In the first four columns, you can see wavelengths that the sonar got from different angles. The last two columns, called name and label respectively, contain an individual object key and the category of that object: rock or mine.

Your task is to rename the first four columns into 'zero_deg', 'sixty_deg', 'ninety_deg', 'straight_angle'. The names of the last two columns should remain unchanged.

You can see a dataset sample below. Note that df_rock is a variable name that contains the whole DataFrame. Just insert your code before the print() function. You don't need to additionally import pandas.

Sample Input 1:

            0°	        60°	        90°	        180°	    name	label
0	0.437427	0.127416	0.258251	0.425674	EAO2	Mine
1	0.421407	0.439730	0.560459	0.424267	PD38	Mine
2	0.205278	0.434688	0.398431	0.532222	JL46	Rock
3	0.094910	0.132226	0.105227	0.156142	M7V9	Rock
4	0.314031	0.272306	0.057900	0.486960	PIYW	Rock

Sample Output 1:

Index(['zero_deg', 'sixty_deg', 'ninety_deg', 'straight_angle', 'name',
       'label'],
      dtype='object')
Write a program in Python 3
# your code here, the dataset is already loaded. The variable name is df_rock.
...

print(df_rock.columns)
___

Create a free account to access the full topic