from pathlib import Path
datapath = Path(r"購入データ")
datas = datapath.glob('*.csv')
import csv


import pandas as pd
csv = pd.read_csv(data,encoding="shift-jis"))


購入金額 = []
返還金額 = []
for data in datas:
    f = open(data,encoding='sjis')
    csvdata = csv.reader(f)
    header=next(csvdata)
    for d in csvdata:
        if d[2] == '合計':
            購入金額.append(d[8])
            返還金額.append(d[11])
    f.close()



p=r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\2021092001734127847931677.csv"
from pathlib import Path
da=Path(p)
import csv
f = open(da,encoding='sjis')
csvdata = csv.reader(f)
お引出金額=[]
お預入金額=[]
for data in csvdata:
    if len(data) == 5 and 'ＪＲＡタ゛イレクト' in data[4]:
        お引出金額.append(data[2])
        お預入金額.append(data[3])

f.close()
sum([int(o) for o in お預入金額])



ps = [
 r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\202101meisai.csv"
,r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\202108meisai.csv"
,r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\202106meisai.csv"
,r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\202105meisai.csv"
,r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\202104meisai.csv"
,r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\202103meisai.csv"
,r"C:\Users\yohei\AppData\Local\Git\statistics\scraping\HorseRace\購入データ\202102meisai.csv"
]
お引出金額=[]
for p in ps:
    da=Path(p)
    f = open(da,encoding='sjis')
    csvdata = csv.reader(f)
    for r in csvdata:
        if len(r) == 12 and 'ＪＲＡダイレクト' in r[3]:
            お引出金額.append(r[4])
    f.close()

sum([int(o) for o in お預入金額])
sum([int(o.replace(',','')) for o in お引出金額])
