Created
March 24, 2017 14:29
-
-
Save anis016/5d7657b015397f172e37a2b7617f5418 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pandas as pd | |
import numpy as np | |
from pandas import DataFrame | |
project_path = os.path.dirname(os.path.abspath(__file__)) | |
data_path = os.path.join(project_path, 'data/') | |
file_row_capacity = os.path.join(data_path, 'row_capacity.csv') | |
file_tickets_sold = os.path.join(data_path, 'tickets_sold.csv') | |
row_capacity = pd.read_csv(file_row_capacity) | |
tickets_sold = pd.read_csv(file_tickets_sold) | |
ticket_dict = {} | |
for index, row in tickets_sold.iterrows(): | |
movie_week = row['calendarweek'] + ":" + row['movie'] | |
if not movie_week in ticket_dict: | |
ticket_dict[movie_week] = {} | |
ticket_dict[movie_week].setdefault(row['auditorium_row'], 0) | |
ticket_dict[movie_week][row['auditorium_row']] += 1 | |
columns = ['calendarweek', 'movie', 'auditorium_row'] | |
df = DataFrame(columns=columns) | |
counter = 0 | |
for key, values in ticket_dict.items(): | |
movie, week = key.split(':') | |
df.loc[counter] = [movie, week, values] | |
counter += 1 | |
print(df) | |
row_dict = {} | |
for index, row in row_capacity.iterrows(): | |
row_dict[row['auditorium_row']] = row['max_seats_per_row'] | |
# print(row_dict) | |
for keyrow, valuesrow in row_dict.items(): | |
for key, values in ticket_dict.items(): | |
audi_row = values.get(keyrow, -1) | |
ticket_dict[key][keyrow] = ( audi_row / valuesrow ) | |
# print(ticket_dict) | |
columns = ['calendarweek', 'movie', 'auditorium_row'] | |
df1 = DataFrame(columns=columns) | |
counter = 0 | |
for key, values in ticket_dict.items(): | |
movie, week = key.split(':') | |
df1.loc[counter] = [movie, week, values] | |
counter += 1 | |
print(df1) | |
# print(df1.groupby('calendarweek').aggregate()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment