Skip to content
Extraits de code Groupes Projets
Valider 4a44c50d rédigé par Adrien Payen's avatar Adrien Payen
Parcourir les fichiers

last update

parent f20b5b83
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
...@@ -23,20 +23,15 @@ def catalog(data_1): ...@@ -23,20 +23,15 @@ def catalog(data_1):
print(data_1.head(100)) print(data_1.head(100))
save_to_csv(data_1) save_to_csv(data_1)
return
# Be careful, you need to ask each time if they want to save the list to a .csv # Be careful, you need to ask each time if they want to save the list to a .csv
def movies(data_1): # register def movies(data_1): # register
films = data_1[data_1['type'] == 'Movie'] # Filter the data to include only movies films = data_1[data_1['type'] == 'Movie'] # Filter the data to include only movies
movie_titles = films['title'].tolist() # Extract movie titles print(films) # Display movie titles
save_to_csv(films)
movie_df = pd.DataFrame({'Movie Titles': movie_titles})
# afficher que les 100 premiers
print(movie_df) # Display movie titles
save_to_csv(movie_df)
return # Be careful, you need to ask each time if they want to save the list to a .csv return # Be careful, you need to ask each time if they want to save the list to a .csv
...@@ -44,13 +39,10 @@ def movies(data_1): # register ...@@ -44,13 +39,10 @@ def movies(data_1): # register
def series(data_1): def series(data_1):
series = data_1[data_1['type'] == 'TV Show'] # Filter the data to include only series series = data_1[data_1['type'] == 'TV Show'] # Filter the data to include only series
series_titles = series['title'].tolist() # Extract series titles
series_df = pd.DataFrame({'Movie Titles': series_titles})
print(series_df) # Display series titles print(series) # Display series titles
save_to_csv(series_df) save_to_csv(series)
return # Be careful, you need to ask each time if they want to save the list to a .csv return # Be careful, you need to ask each time if they want to save the list to a .csv
...@@ -172,37 +164,42 @@ def genre(data_1): ...@@ -172,37 +164,42 @@ def genre(data_1):
def duration(data_1): def duration(data_1):
# Filtrer par type de média
filtered_data = filter_media_type(data_1) filtered_data = filter_media_type(data_1)
# Obtenir la liste de tous les genres possibles
genre_list = [] genre_list = []
for genres in data_1['listed_in'].dropna().str.split(', '): for genres in data_1['listed_in'].dropna().str.split(', '):
for genre in genres: for genre in genres:
if genre not in genre_list and genre != '': if genre not in genre_list and genre != '':
genre_list.append(genre) genre_list.append(genre)
# Afficher la liste des genres possibles
print("List of all possible genres:") print("List of all possible genres:")
genre_list.sort() genre_list.sort()
print(genre_list) print(genre_list)
# Demander à l'utilisateur de saisir le genre
while True: while True:
type_input = input("Enter the type (romantic, action, drama, etc.) to display movies and/or series: ") type_input = input("Enter the type (romantic, action, drama, etc.) to display movies and/or series: ")
# Use FuzzyWuzzy to find the closest match # Utiliser FuzzyWuzzy pour trouver la correspondance la plus proche
matches = process.extractOne(type_input, genre_list) matches = process.extractOne(type_input, genre_list)
if matches[1] >= 80: # Adjust the similarity threshold as needed if matches[1] >= 80: # Ajuster le seuil de similarité si nécessaire
type_input = matches[0] type_input = matches[0]
break break
else: else:
closest_match = matches[0] closest_match = matches[0]
print(f"Invalid genre. The closest match is: {closest_match}") print(f"Invalid genre. The closest match is: {closest_match}")
# Check if the entered genre is correct # Vérifier si le genre saisi est correct
if type_input in genre_list: if type_input in genre_list:
print(f"You selected: {type_input}") print(f"You selected: {type_input}")
else: else:
print(f"You entered: {type_input}, which is not in the list.") print(f"You entered: {type_input}, which is not in the list.")
# Demander le type de tri
print("What type of sorting do you want? ") print("What type of sorting do you want? ")
print("1. Ascending") print("1. Ascending")
print("2. Descending") print("2. Descending")
...@@ -215,20 +212,22 @@ def duration(data_1): ...@@ -215,20 +212,22 @@ def duration(data_1):
else: else:
print("Invalid sort order. Please enter 1 for ascending or 2 for descending.") print("Invalid sort order. Please enter 1 for ascending or 2 for descending.")
type_data = filtered_data[filtered_data['listed_in'].str.lower().str.contains(type_input.lower(), case=False, na=False)] # Filtrer les données en fonction du genre saisi
type_data = filtered_data[filtered_data['listed_in'].str.lower().str.contains(type_input.lower(), case=False, na=False)].copy()
if not type_data.empty: if not type_data.empty:
print(f"\nDisplaying data for {type_input} sorted in {'ascending' if sort_order == '1' else 'descending'} order:") print(f"\nDisplaying data for {type_input} sorted in {'ascending' if sort_order == '1' else 'descending'} order:")
type_data.loc[:, 'duration'] = type_data['duration'].str.extract('(\\d+)').astype(int)
if sort_order == '1': # Extraire les valeurs numériques de la colonne 'duration'
type_data_sorted = type_data.sort_values(by=['type', 'duration'], ascending=[True, True]) type_data['duration'] = type_data['duration'].str.extract('(\\d+)').astype(float)
elif sort_order == '2':
type_data_sorted = type_data.sort_values(by=['type', 'duration'], ascending=[True, False]) # Trier les données en fonction du type et de la durée
type_data_sorted = type_data.sort_values(by=['type', 'duration'], ascending=[True, sort_order == '1'])
# Convertir les valeurs de durée en texte formaté
type_data_sorted['duration'] = type_data_sorted.apply( type_data_sorted['duration'] = type_data_sorted.apply(
lambda row: f"{row['duration']} min" if row['type'].lower() == 'movie' else f"{row['duration']} Season", axis=1 lambda row: f"{int(row['duration'])} min" if row['type'].lower() == 'movie' else f"{int(row['duration'])} Season",
axis=1
) )
print(type_data_sorted) print(type_data_sorted)
...@@ -273,14 +272,32 @@ def director(data_1): ...@@ -273,14 +272,32 @@ def director(data_1):
else: else:
print(f"You entered: {director_input}, which is not in the list.") print(f"You entered: {director_input}, which is not in the list.")
# Menu for sorting order
while True:
print("Select sorting order:")
print("1. Ascending")
print("2. Descending")
sort_order_input = input("Enter the number of your choice: ")
if sort_order_input == '1':
sort_order_bool = True
break
elif sort_order_input == '2':
sort_order_bool = False
break
else:
print("Invalid input. Please enter '1' for Ascending or '2' for Descending.")
order_text = 'ascending' if sort_order_bool else 'descending'
director_data = filtered_data[filtered_data['director'].str.lower().str.contains(director_input.lower(), case=False, na=False)] director_data = filtered_data[filtered_data['director'].str.lower().str.contains(director_input.lower(), case=False, na=False)]
if not director_data.empty: if not director_data.empty:
print(f"\nDisplaying data for movies and/or series directed by {director_input} sorted by release year in ascending order:") print(f"\nDisplaying data for movies and/or series directed by {director_input} sorted by release year in {order_text} order:")
director_data_sorted = director_data.sort_values(by='release_year', ascending=True) director_data_sorted = director_data.sort_values(by='release_year', ascending=sort_order_bool)
print(director_data_sorted) print(director_data_sorted)
save_to_csv(director_data_sorted) save_to_csv(director_data_sorted) # Uncomment this line if you want to save to CSV
else: else:
print(f"No person found with the name {director_input}.") print(f"No person found with the name {director_input}.")
...@@ -560,6 +577,7 @@ def most_rated_recent(data_1, data_2): ...@@ -560,6 +577,7 @@ def most_rated_recent(data_1, data_2):
def parental_code(data_1): def parental_code(data_1):
valid_codes = set(['PG-13', 'TV-MA', 'PG', 'TV-14', 'TV-PG', 'TV-Y', 'TV-Y7', 'R', 'TV-G', 'G', 'NC-17', 'NR', 'TV-Y7-FV', 'UR']) valid_codes = set(['PG-13', 'TV-MA', 'PG', 'TV-14', 'TV-PG', 'TV-Y', 'TV-Y7', 'R', 'TV-G', 'G', 'NC-17', 'NR', 'TV-Y7-FV', 'UR'])
# there is a problem in the csv (values ​​which should not be there). So we sorted
# Filter out entries that are not valid parental codes # Filter out entries that are not valid parental codes
filtered_data = data_1[data_1['rating'].isin(valid_codes)] filtered_data = data_1[data_1['rating'].isin(valid_codes)]
...@@ -650,8 +668,6 @@ def filter_media_type(data): ...@@ -650,8 +668,6 @@ def filter_media_type(data):
print("Invalid choice. Please enter a valid number.") print("Invalid choice. Please enter a valid number.")
# Example usage # Example usage
def basic_statistics(data_1): def basic_statistics(data_1):
# Check if the 'type' and 'country' columns exist in the dataset # Check if the 'type' and 'country' columns exist in the dataset
...@@ -872,7 +888,7 @@ def action() : ...@@ -872,7 +888,7 @@ def action() :
print("Here are the different options available:") print("Here are the different options available:")
print("1. View the entire catalog") print("1. View the entire catalog")
print("2. View all movies in the catalog") print("2. View all movies in the catalog")
print("3. View all series") print("3. View all series in the catalog")
print("4. View all series, movies or both by year") print("4. View all series, movies or both by year")
print("5. View all series, movies or both by country") print("5. View all series, movies or both by country")
print("6. View all series, movies or both by type") print("6. View all series, movies or both by type")
...@@ -927,7 +943,7 @@ def action() : ...@@ -927,7 +943,7 @@ def action() :
basic_statistics(data_1) basic_statistics(data_1)
elif command == "18" : elif command == "18" :
recommandation_algorithm() recommandation_algorithm()
elif command == "STOP" : elif command.upper() == "STOP" :
return False return False
......
...@@ -19,7 +19,7 @@ all_course_MA2 = ("Advanced English 2", "Español avanzado 1", "Responsabilité ...@@ -19,7 +19,7 @@ all_course_MA2 = ("Advanced English 2", "Español avanzado 1", "Responsabilité
file_path = '/coding-project/Data_Base.xlsx' file_path = '/Users/adrien/vscodeworkspace/coding-project/Data_Base.xlsx'
data = pd.read_excel(file_path) data = pd.read_excel(file_path)
excel_file_path = 'export_names.xlsx' excel_file_path = 'export_names.xlsx'
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter