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

data.set_index('Locality', inplace=True)

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

Example:

> import pandas as pd
> df = pd.DataFrame([['ABBOTSFORD', 427000, 448000],
                     ['ABERFELDIE', 534000, 600000]],
                    columns=['Locality', 2005, 2006])

> df
     Locality    2005    2006
0  ABBOTSFORD  427000  448000
1  ABERFELDIE  534000  600000

> df.set_index('Locality', inplace=True)
> df
              2005    2006
Locality                  
ABBOTSFORD  427000  448000
ABERFELDIE  534000  600000

> df.loc['ABBOTSFORD']
2005    427000
2006    448000
Name: ABBOTSFORD, dtype: int64

> df.loc['ABBOTSFORD'][2005]
427000

> df.loc['ABBOTSFORD'].values
array([427000, 448000])

> df.loc['ABBOTSFORD'].tolist()
[427000, 448000]
Answer from Michael Hoff on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › python-pandas-dataframe-set_index
Python | Pandas DataFrame.set_index() - GeeksforGeeks
July 11, 2025 - Now let see some practical examples better understand how to use the Pandas set_index() function. In this example, we set both First Name and Gender as the index columns using the set_index() method with the append and drop parameters.
Discussions

python - Could pandas use column as index? - Stack Overflow
You can change the index as explained already using set_index. You don't need to manually swap rows with columns, there is a transpose (data.T) method in pandas that does it for you: More on stackoverflow.com
🌐 stackoverflow.com
Using a Pandas dataframe index as values for x-axis in matplotlib? [Python 2.7][Matplotlib][Pandas]

The issue is that you passed "site2.index.values" instead of just "site2.index".

More on reddit.com
🌐 r/learnpython
4
7
March 12, 2014
Cannot reindex a non-uniquie index with a method
The way I understand the error, it's saying that you have identical values in timestamp column. By definition, index must use unique keys. I'm not sure if you were trying to address this problem with drop_duplicates(), but, just saying that it wouldn't help, as drop_duplicates() compares rows, not just values in one column. Not sure if this would be possible for you, but... maybe try to groupby on timestamp first, and then make it the index? Seems like you are going to aggregate the data anyways, right? More on reddit.com
🌐 r/learnpython
17
5
January 17, 2021
How do I add new column and hard-coded text to pandas dataframe?

Im on my mobile, but you need to add astype(str) when you concatenate or a lambda function where you pass x as a string before concatenating.

More on reddit.com
🌐 r/learnpython
5
0
November 4, 2017
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Set a column as the DataFrame index with set_index() | note.nkmk.me
January 26, 2024 - The set_index() method of pandas.DataFrame allows you to set an existing column as the index (row labels). pandas.DataFrame.set_index — pandas 2.1.4 documentation How to use set_index()Basic usageKee ...
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › set_index
Python Pandas DataFrame set_index() - Set DataFrame Index | Vultr Docs
December 24, 2024 - The set_index() function in Pandas is used primarily for setting a column or multiple columns as the new index of the DataFrame. One of the main perks of setting a specific column as an index is the increased efficiency in data retrieval operations.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-set-the-first-column-and-row-as-index-in-pandas
How to Set the First Column and Row as Index in Pandas | Saturn Cloud Blog
June 19, 2023 - By default, pandas assigns a numerical index to each row of a DataFrame, starting from zero. However, in some cases, it may be more useful to assign a specific column or row as the index of a DataFrame. For example, if you have a DataFrame that contains sales data for different products, you may want to set the product names as the index so that you can easily look up sales data for a specific product.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas set index to column in dataframe
Pandas Set Index to Column in DataFrame - Spark By {Examples}
November 14, 2024 - In order to set the index to a column in pandas DataFrame use reset_index() method. By using this you can also set single, multiple indexes to a column.
Find elsewhere
🌐
Medium
medium.com › @noorfatimaafzalbutt › understanding-set-index-and-reset-index-in-pandas-6a1b7a27857c
Understanding set_index() and reset_index() in Pandas | by Noor Fatima | Medium
June 28, 2024 - Two essential functions for managing ... multi-level indexing (hierarchical indexing). The set_index() function is used to set one or more existing columns of a DataFrame as its index....
🌐
Appdividend
appdividend.com › 2019 › 01 › 26 › pandas-set-index-example-python-set_index-tutorial
Pandas DataFrame set_index(): Setting an Index Column
September 23, 2025 - It restructures the DataFrame by promoting specified columns to the index. import pandas as pd df = pd.DataFrame( { 'ID': [101, 102, 103, 104, 105, 106, 107], 'Team_Name': ["Lakers", "Patriots", "Yankees", "Lakers", "Red Sox", "Warriors", "Patriots"], 'Wins': [12, 10, 14, 12, 13, 15, 18] } ) print(df) df = df.set_index('ID') print(df)
🌐
Python Examples
pythonexamples.org › pandas-set-column-as-index
Set Column as Index in Pandas DataFrame - Examples
Pandas – Set Column as Index: To set a column as index for a DataFrame, use DataFrame. set_index() function, with the column name passed as argument. You can also setup MultiIndex with multiple columns in the index. In this case, pass the array of column names required for index, to set_index() ...
🌐
PYnative
pynative.com › home › python › pandas › set index in pandas dataframe
Set index in pandas DataFrame
March 9, 2023 - In the below example, we pass a list of existing column labels ‘Name’ and ‘Marks’ to set a multi-level index in the student DataFrame. Note: It throws KeyError for unknown column labels. import pandas as pd student_dict = {'Name': ['Joe', 'Nat', 'Harry'], 'Age': [20, 21, 19], 'Marks': [85.10, 77.80, 91.54]} # create DataFrame from dict student_df = pd.DataFrame(student_dict) print(student_df) # set multi-index student_df = student_df.set_index(['Name', 'Marks']) print(student_df)Code language: Python (python) Run
🌐
W3Schools
w3schools.com › python › pandas › ref_df_set_index.asp
Pandas DataFrame set_index() Method
Make the "name" column become the index of the DataFrame: import pandas as pd data = { "name": ["Sally", "Mary", "John", "Monica"], "age": [50, 40, 30, 40], "qualified": [True, False, False, False] } df = pd.DataFrame(data) newdf = df.set_index('name') Try it Yourself » ·
🌐
Kanaries
docs.kanaries.net › topics › Pandas › pandas-set-index
How to Use Pandas Set Index – Kanaries
This will be the new index of your DataFrame. drop (Default: True): If set to True, the column you're setting as the new index will be deleted from the DataFrame.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › pandas tutorial › pandas set index
Pandas Set Index | How to Set Column as Index in Pandas DataFrame?
April 10, 2023 - So, we add the code, data.set_index(‘name’), and finally print the output. In the output, as you can see, the column ‘name’ has also been printed as a variable and it is completely separated from all the other columns. This is because it acts like just another index value and all the names act as index values for the rows. ... import pandas as pd data = pd.DataFrame({ "name":["Span","Such","Vetts","Deep","Apoo","Sou","Ath","Pri","Pan","Pran","Anki"] ,"age":[25,26,27,28,29,30,31,32,33,34,35] ,"sal":[30000,40000,50000,60000,70000,80000,90000,95000,96000,97000,98000] ,"expense":[20000,30000,40000,50000,60000,70000,80000,85000,86000,87000,88000]}) data_copy=data.copy() data_copy.set_index('name', inplace = True) print(data_copy)
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.index.html
pandas.DataFrame.index — pandas 3.0.3 documentation
>>> df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'], ... 'Age': [25, 30, 35], ... 'Location': ['Seattle', 'New York', 'Kona']}, ... index=([10, 20, 30])) >>> df.index Index([10, 20, 30], dtype='int64') In this example, we create a DataFrame with 3 rows and 3 columns, including Name, Age, and Location information. We set the index labels to be the integers 10, 20, and 30.
🌐
Python Guides
pythonguides.com › set-column-as-index-in-python-pandas
Set First Column As Index In Pandas Python
May 26, 2025 - Learn 5 simple methods to set the first column as an index in Pandas Python with real-world examples. Master DataFrame indexing for more efficient data analysis
🌐
Programiz
programiz.com › python-programming › pandas › methods › set_index
Pandas set_index()
The set_index() method is used to set the index of a DataFrame. The set_index() method in Pandas is used to set the index of the DataFrame. This method allows us to use one or more columns as the index. Once set, the specified column(s) will become the new row labels of the DataFrame.
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-set_index.php
Pandas DataFrame: set_index() function - w3resource
August 19, 2022 - Pandas DataFrame - set_index() function: The set_index() function is used to set the DataFrame index using existing columns.
🌐
Codegive
codegive.com › blog › pandas_set_index.php
Mastering <code>pandas set index</code>: Unlock Data Power for Faster Analysis & Clarity!
Original DataFrame: city temperature humidity 0 New York 25 70 1 Los Angeles 30 60 2 Chicago 20 75 3 Houston 28 65 Original Index: RangeIndex(start=0, stop=4, step=1) DataFrame after setting 'city' as index: temperature humidity city New York 25 70 Los Angeles 30 60 Chicago 20 75 Houston 28 65 New Index: Index(['New York', 'Los Angeles', 'Chicago', 'Houston'], dtype='object', name='city') Notice how 'city' is no longer a regular column, but now serves as the DataFrame's index. This is the most common use case. import pandas as pd products_data = { 'product_id': ['A001', 'A002', 'B001', 'C005'], 'product_name': ['Laptop', 'Mouse', 'Keyboard', 'Monitor'], 'price': [1200, 25, 75, 300], 'stock': [50, 200, 150, 80] } products_df = pd.DataFrame(products_data)