Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to reshape dataframe in python

# Importing modules
import pandas as pd
import numpy as np

# Create a dataframe
df = pd.DataFrame(np.random.randn(
    5, 4), index='A B C D E'.split(), columns='W X Y Z'.split())
print(df)

# Reshape the dataframe
df = df.stack().reset_index()
print(df)
 
PREVIOUS NEXT
Tagged: #reshape #dataframe #python
ADD COMMENT
Topic
Name
5+9 =