To set a specific column as the index of a DataFrame in pandas, you can use the set_index()
function. Here is an example:
main.py269 chars12 lines
In this example, the 'Name' column is set as the index using set_index('Name')
. The resulting DataFrame will have the 'Name' column as the index instead of the default integer index.
Note that the set_index()
function returns a new DataFrame with the modified index. If you want to modify the DataFrame in place, you can pass the inplace=True
argument:
main.py35 chars2 lines
This will modify the original DataFrame df
and set the 'Name' column as the index.
gistlibby LogSnag