-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitial.py
36 lines (26 loc) · 831 Bytes
/
initial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sys
FILE_1 = 'data/anime.csv'
FILE_2 = 'data/rating.csv'
PATH_OUT = 'data/'
def outputTopNAnime(df, n):
df = df[df['members'] > 500]
top_n = df.sort_values(by='rating', ascending=False)
top_n = top_n.head(n)
top_n.to_csv(PATH_OUT+'anime_popular.csv', header=True, index=False)
def main():
anime = pd.read_csv(FILE_1)
rating = pd.read_csv(FILE_2)
# clean ratings
rating = rating.dropna()
rating = rating[rating['rating'] > -1]
# clean anime
anime = anime[anime['genre'].str.contains('Hentai') == False]
anime = anime[anime['type'] != 'Music']
anime = anime[anime['members'] > 100]
# output top 1000 most popular anime
outputTopNAnime(anime, 250)
if __name__ == '__main__':
main()