Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas set a column as index

df = pd.DataFrame({'month': [1, 4, 7, 10],
                   'year': [2012, 2014, 2013, 2014],
                   'sale': [55, 40, 84, 31]})

df.set_index('month')
Comment

set index to column pandas

# method A
df = df.set_index('col')
# method B
df['col'] = df.index
Comment

Set column as index with pandas

import pandas as pd

# Set column as index
df = df.set_index("column")

# Display DataFrame
print(df)
Comment

PREVIOUS NEXT
Code Example
Python :: exception get line number python 
Python :: how to get random word from text file in python 
Python :: python roman to integer 
Python :: height width image opencv 
Python :: clear console python 
Python :: selenium-screenshot python 
Python :: pandas read_csv drop last column 
Python :: python how to find the highest number in a dictionary 
Python :: pytest ignore warnings 
Python :: load custom font pygame 
Python :: pygame quit 
Python :: getting dummies and input them to pandas dataframe 
Python :: check cuda version pytorch 
Python :: install pandas in python mac 
Python :: tkinter load image 
Python :: how to check opencv version using python 
Python :: How to Add a Title to Seaborn Plots 
Python :: sum of all nan values pandas 
Python :: python print dict pretty 
Python :: python - remove scientific notation 
Python :: python radians to degrees 
Python :: add all string elements in list python 
Python :: python discord webhook 
Python :: python merge pdfs 
Python :: python get copied text 
Python :: Show the records that have nan values 
Python :: get size of window tkinter 
Python :: python querystring parse 
Python :: how to find the calendar week python 
Python :: xgboost feature importance 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =