import csv
funnel_gender = {}
funnel_device={}
funnel_month={}
funnel_set={"1_home_page":0, "2_search_page":0, "3_payment_page":0, "4_payment_confirmation_page":0}
with open(r'C:\Users\79101\Desktop\Новая папка\click_stream3.csv', mode='r') as csv_file: # открываем файл
csv_reader = csv.DictReader(csv_file) # читаем файл
for row in csv_reader:
page=list(row.items())[1][1]
data=list(row.items())[2][1][:-3]
device=list(row.items())[3][1]
gender = list(row.items())[4][1]
if gender not in funnel_gender:
funnel_gender[gender] = funnel_month.copy()
if data not in funnel_gender[gender]:
funnel_gender[gender][data] = funnel_set.copy()
if page=="1_home_page":
funnel_gender[gender][data][page]+=1
elif page=="2_search_page":
funnel_gender[gender][data][page]+=1
elif page=="3_payment_page":
funnel_gender[gender][data][page]+=1
else:
funnel_gender[gender][data][page]+=1
print(funnel_gender)