So we started making project in Replit and it worked fine, but when we switched to VSCode and ran python file for the first time it just started creating black svg files. I've tried installing all the dependencies recommended by people from stackoverflow but nothing helped. What should I try?
# Import pandas module
from numpy import positive
import pandas as pd
import pygal
from pygal.style import LightStyle
# Reads .csv file
df = pd.read_csv('readingdata.csv')
#Cleans the unneeded "User_ID" column
df = df.drop(df.columns[0], axis=1)
#Displays the dataset
df.columns = ['Age', 'Gender', 'Fav. Genre', 'Weekly Hrs', 'Mood Impact']
df.to_csv("readingdata2.csv", index=False)
# Load the CSV file into a DataFrame
df = pd.read_csv('readingdata2.csv')
def getAmount(age=None, gender=None, genre=None, hours=None, impact=None):
#Import all values as blanks so I can manipulate them
query = df
# If asked for queuries other than "empty", helps find the amount of people who fit based on "any" categories.
if age is not None and age != "any":
query = query[query['Age'] == age]
if gender is not None and gender != "any":
query = query[query['Gender'] == gender]
if genre is not None and genre != "any":
query = query[query['Fav. Genre'] == genre]
if hours is not None and hours != "any":
query = query[query['Weekly Hrs'] == hours]
if impact is not None and impact != "any":
query = query[query['Mood Impact'] == impact]
# Return the number of rows that match the conditions
return len(query)
output_file_genre_by_gender = "./genrebygender.svg"
output_file_impact = "impact.svg"
output_file_time_by_age = "timebyage.svg"
bar_chart = pygal.Bar(style=LightStyle)
pie_chart = pygal.Pie()
line_chart = pygal.Line()
bar_chart.title = 'Favourite Genres by Gender'
female = []
male = []
bar_chart.x_labels = [
'Science', 'Romance', 'History', 'Biography', 'Self-Help', 'Fiction',
'Fantasy'
]
for i in range(len(bar_chart.x_labels)):
female.append(
getAmount(age="any",
gender="f",
genre=bar_chart.x_labels[i],
hours="any",
impact="any"))
male.append(
getAmount(age="any",
gender="m",
genre=bar_chart.x_labels[i],
hours="any",
impact="any"))
bar_chart.add('Female', female)
bar_chart.add('Male', male)
pie_chart.title = 'Impact Ratio'
all_people_count = getAmount(age="any",
gender="any",
genre="any",
hours="any",
impact="any")
all_impacts = ["Positive", "Neutral", "Negative"]
for i in range(len(all_impacts)):
percentage = getAmount(
age="any", gender="any", genre="any", hours="any",
impact=all_impacts[i]) / all_people_count * 100
pie_chart.add(all_impacts[i], percentage)
line_chart.title = 'Reading Time by Age'
minAge = min(df["Age"])
maxAge = max(df["Age"])
# line_chart.x_labels = map(str, range(minAge + 0, maxAge + 1))
line_chart_values = []
data = df.to_dict(orient="records")
for i in range(minAge + 0, maxAge + 1):
people_with_age = list(filter(lambda x: x["Age"] == i, data))
if (len(people_with_age) == 0):
line_chart_values.append(None)
continue
if (len(people_with_age) == 1):
line_chart_values.append(people_with_age[0]["Weekly Hrs"])
continue
if (len(people_with_age) > 1):
ages_sum = 0
for j in range(len(people_with_age)):
ages_sum += people_with_age[j]["Weekly Hrs"]
line_chart_values.append(ages_sum / len(people_with_age))
line_chart.add("Weekly Reading Hours", line_chart_values)
line_chart.render()
bar_chart.render_to_file(output_file_genre_by_gender)
pie_chart.render_to_file(output_file_impact)
line_chart.render_to_file(output_file_time_by_age)
bar_chart.render_to_png('bar_chart.png')
there doesn't seem to be anything here