我有我創建了一個數據透視表(數據透視表)循環:使用通過蟒蛇透視表
pivotTable= dayData.pivot_table(index=['sector'], aggfunc='count')
已經產生了以下透視表:
sector id
broad_sector
Communications 2 2
Utilities 3 3
Media 3 3
可能有人讓我知道是否有方法通過數據透視表循環將索引值和扇區總數分配給各個變量sectorName
和sectorCount
我試過了:
i=0
while i <= lenPivotTable:
sectorName = sectorPivot.index.get_level_values(0)
sectorNumber = sectorPivot.index.get_level_values(1)
i=i+1
返回第一個循環迭代:
sectorName = 'Communications'
sectorCount = 2
第二循環迭代:
sectorName = 'Utilities'
sectorCount = 3
第三循環迭代:
sectorName = 'Media'
sectorCount = 3
但可以不能讓它工作。任何幫助表示讚賞
目前還不清楚是什麼你會實現。你能發佈一個理想的結果集嗎? – MaxU
我不明白你的問題是什麼。這是關於[問] –