Search code examples
pythonpandasscalaapache-sparkxlsx

Partial Pivoting In Pandas SQL Or Spark


Partial Pivoting In Pandas SQL Or Spark

Make the Year remain as Rows, and have the States Transpose to columns Take Pecentage value of a Gender Male Race White,

Input

Blockquote

Output

Blockquote


Solution

  • Answer Posted By @Peter Leimbigler as comment

    df.pivot_table(index='Year', columns='States', values='Percentage')
    

    I tried it works.. Thanks Peter