def run(f): reader = get_csv_reader(f) main_cat_success_counts = {} def add_count_to_main_category(row): main_category = row[3] main_cat_success_counts.setdefault(main_category, 0) main_cat_success_counts[main_category] += 1 each_funded_project(reader, add_count_to_main_category) restart_pointer(f) all_main_cat_counts = get_all_main_cat_counts(reader) main_cat_success_rates = get_main_cat_sucess_rates( all_main_cat_counts, main_cat_success_counts) best_main_category = max(main_cat_success_rates.items(), key=operator.itemgetter(1)) print(best_main_category[0] + " has the best succes rate with a " + str(best_main_category[1]) + " success rate.") return best_main_category[0]
def sum_nationality(f): csv_data = get_csv_reader(f) player_counter = {} for row in csv_data: player_counter.setdefault(row[14], 0) player_counter[row[14]] += 1 return player_counter
def sum_ide_users(f): csv_data = get_csv_reader(f) player_counter = {} for row in csv_data: player_counter.setdefault(row[2], 0) player_counter[row[2]] += 1 return player_counter
def avg_of_row(f, row_num): csv_data = get_csv_reader(f) total_value = 0 counter = 0 for row in csv_data: total_value += float(row[row_num]) counter += 1 return round(total_value / counter, 2)
def run(f): csv_reader = get_csv_reader(f) biggest_transaction_amount = 0 for row in csv_reader: amount = float(row[5]) if biggest_transaction_amount < amount: biggest_transaction_amount = amount print(biggest_transaction_amount)
def get_teams_with_cumulative_player_worth(f): csv_reader = get_csv_reader(f) result_data = {} for row in csv_reader: team_name = row[3] if team_name != '': player_worth = float(row[16]) result_data.setdefault(team_name, 0) result_data[team_name] += player_worth return result_data
def run(f): reader = get_csv_reader(f) successful_count = 0 for row in reader: state = row[9] == "successful" enough_pledged = float(row[13]) > 5000 if state and enough_pledged: successful_count += 1 print(successful_count)
def run(f): reader = get_csv_reader(f) pledged_amounts = [] def add_pledged_amount(row): pledged_amount = row[13] if pledged_amount.strip() != '': pledged_amounts.append(float(pledged_amount)) each_funded_project(reader, add_pledged_amount) pledged_amounts.sort() median = np.median(pledged_amounts) print(median)
def get_players_with_release_and_worth_diff(f): csv_reader = get_csv_reader(f) processed_data = {} for row in csv_reader: release_clause = row[18] if release_clause != '': player_name = row[2] worth = float(row[16]) release_clause = float(release_clause) processed_data.setdefault(player_name, {}) processed_data[player_name] = { 'worth': worth, 'difference': release_clause - worth } return processed_data
def run(f): csv_reader = get_csv_reader(f) buycounter = 0 sellcounter = 0 for row in csv_reader: if row[6] == "BUY": buycounter += 1 if row[6] == "SELL": sellcounter += 1 if buycounter >= sellcounter: print("The most common is Buy which was: ") print(buycounter) else: print("the most common is Sell which was: ") print(sellcounter)
def run(f, best_main_category): categories_successful_projects_count = {} reader = get_csv_reader(f) best_main_category for row in reader: main_category = row[3] category = row[2] if main_category == best_main_category: categories_successful_projects_count.setdefault(category, 0) categories_successful_projects_count[category] += 1 category_most_successful = max( categories_successful_projects_count.items(), key=operator.itemgetter(1))[0] print(category_most_successful)
def run(f): csv_reader = get_csv_reader(f) transaction_counts = {} for row in csv_reader: date = iso8601.parse_date(row[1]) key = str(date.year) + "-0" + str(date.month) + "-0" + str( date.day) + " 0" + str(date.hour) + ":00" transaction_counts.setdefault(key, 0) transaction_counts[key] += 1 for item in transaction_counts.items(): x = item[0] y = item[1] fig = plt.scatter(x, y, s=200) print(item[0], " -> ", item[1], " transactions") plt.title("Graph of a days transactions", fontsize=20) plt.xlabel("Hours", fontsize=14) plt.ylabel("Transaction numbers", fontsize=14) plt.show(fig)