Home > Software design >  Python how to automate define a function for pivot table and for loop
Python how to automate define a function for pivot table and for loop

Time:01-11

I made a random table and I want to transfer it to pivot tables, using define a function and also for loop. And I want to make the code reusable and automatically.

enter image description here

CodePudding user response:

Read the file in pandas. See the documentation on read_excel and read_csv

Then,

df = pd.set_index(['Date', 'State', 'Name').unstack()
df

Then you can write df to to another excel or csv file.

  •  Tags:  
  • Related