0
我有一個這樣的熊貓數據幀,我想用pd.pivot_table嘗試使用熊貓樞像Excel數據透視
import pandas
df = pd.DataFrame({"Id":[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10],
"Error":[0, 99, 0, 0, 0, 98, 0, 0, 0, 0, 33, 0, 23, 0, 0, 0, 83, 0]})
我試着轉動像這樣(支點在Excel中製作)轉動:
我嘗試這樣做:
dfPivot = pd.pivot_table(df, index = "Id", columns = df.Error.unique(), values = "Error", aggfunc="count")
我弗洛翼錯誤。
AssertionError: Grouper and axis must be same length
在此先感謝您。
謝謝你的回答!我用你的解決方案。 – Hangon