| [ Web Proxy ] |
| Viewing: https://dataframes.bigquery.dev/reference/api/bigframes.pandas.DataFrame.set_index.html | [Back] [Original] |
Section Navigation
Set the DataFrame index using existing columns.
Set the DataFrame index (row labels) using one existing column. The index can replace the existing index.
Examples:
>>> df = bpd.DataFrame({'month': [1, 4, 7, 10],
... 'year': [2012, 2014, 2013, 2014],
... 'sale': [55, 40, 84, 31]})
>>> df
month year sale
0 1 2012 55
1 4 2014 40
2 7 2013 84
3 10 2014 31
[4 rows x 3 columns]
Set the month column to become the index:
>>> df.set_index('month')
year sale
month
1 2012 55
4 2014 40
7 2013 84
10 2014 31
[4 rows x 2 columns]
Create a MultiIndex using columns year and month:
>>> df.set_index(['year', 'month'])
sale
year month
2012 1 55
2014 4 40
2013 7 84
2014 10 31
[4 rows x 1 columns]
keys A label. This parameter can be a single column key.
drop Delete columns to be used as the new index.
Changed row labels.
KeyError If key(s) are not in the columns.
Copyright 2019, Google.
Created using Sphinx 8.1.3.
Built with the PyData Sphinx Theme 0.19.0.
| Web Proxy Viewer | New URL | Original Page |