Skip to content
Advertisement

Could pandas use column as index?

I have a spreadsheet like this:

JavaScript

I don’t want to manually swap the column with the row. Could it be possible to use pandas reading data to a list as this:

JavaScript

Advertisement

Answer

Yes, with pandas.DataFrame.set_index you can make 'Locality' your row index.

JavaScript

If inplace=True is not provided, set_index returns the modified dataframe as a result.

Example:

JavaScript
Advertisement