I need some help
I have the follow CSV file with this Data Frame:
how could I transfer the data of cases in columns week 1, week 2 (...) using Python and Pandas? It would be something like this:
I need some help
I have the follow CSV file with this Data Frame:
how could I transfer the data of cases in columns week 1, week 2 (...) using Python and Pandas? It would be something like this:
 
    
    x = (
    df.pivot_table(
        index=["city", "population"],
        columns="week",
        values="cases",
        aggfunc="max",
    )
    .add_prefix("week ")
    .reset_index()
    .rename_axis("", axis=1)
)
print(x)
Prints:
  city  population  week 1  week 2
0    x       50000       5      10
1    y       88000       2      15
