Computer scienceData scienceInstrumentsPandasStoring data with pandas

Accessing data in a DataFrame

Set a new index

Report a typo

You are working with the 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 an object: rock or mine.

Suppose that now, for convenience, you want to set the column called name as index.

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.

Sample Input 1:

        zero_deg	sixty_deg	ninety_deg	straight_angle	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(['EAO2', 'PD38', 'JL46', 'M7V9', 'PIYW'], dtype='object', name='name')
Write a program in Python 3
# your code here, the dataset is already loaded. The variable name is df_rock.
...

print(df_rock.index)
___

Create a free account to access the full topic