generated from DS4200-S23-Class/project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_exploration.py
64 lines (33 loc) · 1.63 KB
/
data_exploration.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pandas as pd
import matplotlib as plt
from datetime import datetime
import re
filename = 'netflix_titles.csv'
def calc_complexity(string):
''' Automated Readability Index '''
string = string.lower()
sentence_count = max([len(string.split('.')[:-1]), 1])
word_count = len(string.split())
char_count = len(re.sub(r'\W+', '', string))
return round(4.71 * (char_count / word_count) + 0.5 * (word_count / sentence_count) - 21.43)
def main():
netflix_df = pd.read_csv(filename)
netflix_df.set_index('show_id', inplace=True)
netflix_df.dropna(inplace=True)
netflix_df = netflix_df[(netflix_df['country'] == 'United States') & (netflix_df['type'] == 'Movie')]
netflix_df['duration'] = list(map(lambda x: x.split()[0], netflix_df['duration']))
netflix_df['date_added'] = list(map(lambda x: datetime.strptime(x, '%B %d, %Y').date(),
netflix_df['date_added']))
netflix_df['complexity'] = list(map(calc_complexity, netflix_df['description']))
categories = [row.split(',') for row in list(netflix_df['listed_in'])]
all_categories = sum(categories, [])
unique_categories = set([cat[1:] if cat[0] == ' ' else cat for cat in all_categories])
for category in list(unique_categories):
encoding = list(map(lambda x: 1 if category in x else 0, netflix_df['listed_in']))
netflix_df[category] = encoding
netflix_df.drop(columns=['country', 'type', 'description'], inplace=True)
netflix_df = netflix_df.astype({'complexity':'float'})
netflix_df.to_csv('testing_3.csv')
line.
if __name__ == '__main__':
main()