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 :: python list distinct 
Python :: numpy correlation 
Python :: rename columns in datarame pandas 
Python :: what is the purpose of the judiciary 
Python :: import a txt file into python 
Python :: Finding the Variance and Standard Deviation of a list of numbers in Python 
Python :: index of sorted list python 
Python :: how to sort a column with mixed text number 
Python :: dataframe split column 
Python :: parquet pyspark 
Python :: run sql query on pandas dataframe 
Python :: python pop up box 
Python :: get all values of a dict python 
Python :: python file name from absolute path 
Python :: on message discord py 
Python :: how to install python 2 
Python :: tensorflow keras save model 
Python :: torchviz 
Python :: pandas join two series on index 
Python :: cprofile implementation 
Python :: how to import tkinter in python 
Python :: How do you print multiple things on one statement in Python? 
Python :: how to sort in greatest to least python 
Python :: https flask 
Python :: pickle.load python 
Python :: python transform two columns to a list combine 
Python :: remove blanks from list python 
Python :: play music with time in python 
Python :: find rows in dataframe from another dataframe python 
Python :: django static url 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =