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 Overflowpython - Could pandas use column as index? - Stack Overflow
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.comCannot reindex a non-uniquie index with a method
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.comVideos
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]
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:
> df = pd.DataFrame([['ABBOTSFORD', 427000, 448000],
['ABERFELDIE', 534000, 600000]],
columns=['Locality', 2005, 2006])
> newdf = df.set_index('Locality').T
> newdf
Locality ABBOTSFORD ABERFELDIE
2005 427000 534000
2006 448000 600000
then you can fetch the dataframe column values and transform them to a list:
> newdf['ABBOTSFORD'].values.tolist()
[427000, 448000]