Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

take columns to rows in pandas

df1 = (df.set_index(["location", "name"])
         .stack()
         .reset_index(name='Value')
         .rename(columns={'level_2':'Date'}))
print (df1)
  location  name        Date  Value
0        A  test    Jan-2010     12
1        A  test    Feb-2010     20
2        A  test  March-2010     30
3        B   foo    Jan-2010     18
4        B   foo    Feb-2010     20
5        B   foo  March-2010     25
Comment

PREVIOUS NEXT
Code Example
Python :: como instalar python en ubuntu 20.04 
Python :: python count appearances in list 
Python :: virtual environment python 
Python :: python call function that need args with decorator 
Python :: get ip address 
Python :: command for python shell 
Python :: speech enhancement techniques 
Python :: change part of a text file python 
Python :: numpy insert 
Python :: Create a hexadecimal colour based on a string with python 
Python :: import random python 
Python :: replace nan in pandas column with mode and printing it 
Python :: python re.split() 
Python :: comments in python 
Python :: Excel file format cannot be determined, you must specify an engine manually 
Python :: python string: .strip() 
Python :: loop for python 
Python :: python remove character from string 
Python :: if loop python 
Python :: python how to vectorize a function 
Python :: bitbucket rest api python example 
Python :: test pypi 
Python :: pandas df mode 
Python :: python uml 
Python :: function composition python 
Python :: python list to arguments 
Python :: os.path.sep.join 
Python :: second highest value in list python 
Python :: python string: .title() 
Python :: dockerfile example 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =