import pandas as pd
import os
import numpy as np
path=os.getcwd()
print(path)
def2=pd.read_csv('c:\python\sample2.csv')
print(def2)
table=pd.pivot_table(def2,values='price',
index=['date'], columns=['item'],aggfunc=np.sum)
print()
print("ピボット集計 結果")
print(table)
==== RESTART: C:/Users/ooshi/AppData/Local/Programs/Python/Python39/pandasCloss.py ====
C:\Users\ooshi\AppData\Local\Programs\Python\Python39
date item price
0 2015-01-01 apple 300
1 2015-01-01 apple 300
2 2015-01-01 orange 250
3 2015-01-02 orange 240
4 2015-01-02 orange 240
5 2015-01-02 banana 260
ピボット集計 結果
item apple banana orange
date
2015-01-01 600.0 NaN 250.0
2015-01-02 NaN 260.0 480.0
>>>
コメント
コメントを投稿