enter image description here
I want this but got that
enter image description here
I want to transfer 2 columns at the same time, but they are directly flattened.
import pandas as pd
ll = [
["ci", "2024-01", "100", "10"],
["test", "2024-01", "100", "10"],
["prd", "2024-01", "100", "10"],
["ci", "2024-02", "100", "10"],
["test", "2024-02", "100", "10"],
["prd", "2024-02", "100", "10"],
["ci", "2024-03", "100", "10"],
["test", "2024-03", "100", "10"],
["prd", "2024-03", "100", "10"],
]
df = pd.DataFrame(ll)
df.columns = [
"account",
"month",
"cost1",
"cost2",
]
df1 = pd.pivot(
df,
index="account",
columns="month",
values=["cost1", "cost2"],
)
print(df1)