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

Is there a way to address Pandas dataframe by column index instead of name?
Yes. Using The column index is fine, because I will always want the information from column H. It’s the headers in my excel file (changed to a panda df) that will change. ... I might be missing something and sorry if I am. But is it as simple as df.iloc[0,4] Will give 1st row and 5th column More on reddit.com
🌐 r/learnpython
12
0
December 12, 2020
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
loading a csv into a dataframe with a datetime as an index

You can by specifying the index_col keyword as the column position, as an int, that should be used as the index and the parse_dates keyword as True. Example:

# Pretend the dates are in the 2nd column
df = pd.read_csv('bunch_of_dated_data.csv', index_col=1, parse_dates=True)
More on reddit.com
🌐 r/learnpython
5
9
October 3, 2017
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
🌐
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 - By default, the column specified as the index is removed from the data columns. Setting drop=False keeps the specified column in the data columns. print(df.set_index('name', drop=False)) # name age state point # name # Alice Alice 24 NY 64 # Bob Bob 42 CA 92 # Charlie Charlie 18 CA 70 # Dave Dave 68 TX 70 # Ellen Ellen 24 CA 88 # Frank Frank 30 NY 57 ... In pandas, you can set a MultiIndex, which enables hierarchical, multi-level indexing.
🌐
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 - In multi-level indexing, also known as hierarchical indexing, you can set multiple columns as the index. This is useful for more complex data structures where you need to identify rows uniquely by multiple keys. ... import pandas as pd # Sample DataFrame data = { 'animal': ['cat', 'cat', 'dog', 'dog'], 'breed': ['Siamese', 'Persian', 'Labrador', 'Beagle'], 'age': [2, 3, 7, 5], 'name': ['Whiskers', 'Fluffy', 'Buddy', 'Charlie'] } df = pd.DataFrame(data) # Set 'animal' and 'breed' as a multi-level index df_multi_index = df.set_index(['animal', 'breed']) print(df_multi_index)
🌐
CodeSignal
codesignal.com › learn › courses › python-libraries-for-data-analysis › lessons › navigating-dataframes-with-index-column-and-data-locating-in-pandas
Navigating DataFrames with Index Column and Data ...
The Pandas' set_index() function allows us to set a custom index. To reset the index to its default state, we use reset_index(). To better understand these functions, let's consider an example in which we create an index using unique IDs: In this example, ID column is displayed as an index.
Find elsewhere
🌐
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 - Pandas is a powerful library in Python widely used for data manipulation and analysis, particularly through its prominent DataFrame structure. Among the numerous functionalities provided by the DataFrame, one key method is set_index(). This method is crucial when you need to set a specific column as the index of the DataFrame, which can be pivotal for data slicing, dicing, and more efficient retrievals.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas set column as index in dataframe
Pandas Set Column as Index in DataFrame - Spark By {Examples}
December 12, 2024 - You can set pandas column as index by using DataFrame.set_index() method and DataFrame.index property. What is an Index in pandas? The row label of
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › pandas-dataframe-index
Pandas Dataframe Index - GeeksforGeeks
March 24, 2026 - ... import pandas as pd data = ... row = df.loc['Alice'] print(row) ... The set_index() method is used to change the index of a DataFrame by setting one or more columns as the new index....
🌐
Pandas
pandas.pydata.org › docs › user_guide › indexing.html
Indexing and selecting data — pandas 3.0.3 documentation
A boolean array (any NA values will be treated as False). A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above). A tuple of row (and column) indices whose elements are one of the above inputs.
🌐
Its Linux FOSS
itslinuxfoss.com › home › python › how to set columns as index in pandas dataframe?
How to Set Columns as Index in Pandas DataFrame? – Its Linux FOSS
January 29, 2023 - To set columns as an index in Pandas DataFrame, the “set_index()” function and the “index” attribute are used in Python. We can set the single or more than one column as a DataFrame index.
🌐
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 » ·
🌐
W3Schools
w3schools.com › python › pandas › ref_df_reset_index.asp
Pandas DataFrame reset_index() Method
import pandas as pd data = { "name": ... df.reset_index() print(newdf) Try it Yourself » · The reset_index() method allows you reset the index back to the default 0, 1, 2 etc indexes....
🌐
Pandas
pandas.pydata.org › docs › reference › indexing.html
Index objects — pandas 3.0.2 documentation
Many of these methods or variants thereof are available on the objects that contain an index (Series/DataFrame) and those should most likely be used before calling these methods directly · Index([data, dtype, copy, name, tupleize_cols])
🌐
Statology
statology.org › home › pandas: how to use first column as index
Pandas: How to Use First Column as Index
August 19, 2022 - Suppose we have the following existing ... 18 5 1 B 22 7 2 C 19 7 3 D 14 9 4 E 14 12 5 F 11 9 6 G 20 9 7 H 28 4 · We can use the set_index() function to set the team column as the index column:...
🌐
GeeksforGeeks
geeksforgeeks.org › python › set-the-first-column-and-row-as-index-in-pandas
Set the First Column and Row as Index in Pandas - GeeksforGeeks
July 23, 2025 - Original DataFrame: A B C 0 1 4 7 1 2 5 8 2 3 6 9 DataFrame with custom row and column labels: ColA ColB ColC Row1 1 4 7 Row2 2 5 8 Row3 3 6 9 · Another way to set the index is by using a range of numbers. Here's how: ... import pandas as pd # Create a sample DataFrame data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]} df = pd.DataFrame(data) print("Original DataFrame:") print(df) # Set the index using a range starting from 1 df.index = range(1, len(df) + 1) # Display the DataFrame with a numeric index print("\nDataFrame with a numeric index:") print(df)
🌐
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)
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas set_index() – set index to dataframe
Pandas set_index() - Set Index to DataFrame - Spark By {Examples}
December 12, 2024 - Index can be set while creating a pandas DataFrame, use set_index() method to set indices to existing DataFrmae. You can also set index from a List, Series or DataFrame. hence, you can have mutliple indices to the DataFrame.