mirror of
https://github.com/kristoferssolo/LU-Data-Visualisation.git
synced 2025-10-21 20:10:40 +00:00
feat: add file reader
This commit is contained in:
parent
b61e3fa21f
commit
950ed3017a
4
main.py
Normal file → Executable file
4
main.py
Normal file → Executable file
@ -2,6 +2,8 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from data.visualize import visualize
|
||||
|
||||
from loguru import logger
|
||||
|
||||
logger.add(
|
||||
@ -15,7 +17,7 @@ logger.add(
|
||||
|
||||
@logger.catch
|
||||
def main() -> None:
|
||||
pass
|
||||
visualize()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -6,15 +6,21 @@ authors = [{ name = "Kristofers Solo", email = "dev@kristofers.xyz" }]
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
license = { text = "MIT" }
|
||||
dependencies = ["attrs==23.1.0", "loguru==0.7.2"]
|
||||
dependencies = [
|
||||
"openpyxl==3.1.2",
|
||||
"attrs==23.1.0",
|
||||
"loguru==0.7.2",
|
||||
"matplotlib==3.8.2",
|
||||
"pandas==2.1.4",
|
||||
]
|
||||
|
||||
[tool.mypy]
|
||||
check_untyped_defs = true
|
||||
disallow_any_generics = true
|
||||
ignore_missing_imports = true
|
||||
no_implicit_optional = true
|
||||
no_implicit_reexport = true
|
||||
show_error_codes = true
|
||||
# no_implicit_optional = true
|
||||
# no_implicit_reexport = true
|
||||
# show_error_codes = true
|
||||
strict_equality = true
|
||||
warn_redundant_casts = true
|
||||
warn_return_any = true
|
||||
|
||||
@ -1,2 +1,5 @@
|
||||
attrs>=23.1.0
|
||||
loguru>=0.7.2
|
||||
matplotlib>=3.8.2
|
||||
openpyxl>=3.1.2
|
||||
pandas>=2.1.4
|
||||
|
||||
13
src/data/read.py
Normal file
13
src/data/read.py
Normal file
@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def read_file(file_name: Path) -> pd.DataFrame:
|
||||
"""Reads a file and returns a pandas DataFrame."""
|
||||
return pd.read_excel(file_name)
|
||||
|
||||
|
||||
def base_path() -> Path:
|
||||
"""Returns the base path of the project."""
|
||||
return Path(__file__).parent.parent.parent
|
||||
24
src/data/visualize.py
Normal file
24
src/data/visualize.py
Normal file
@ -0,0 +1,24 @@
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from data.read import base_path, read_file
|
||||
|
||||
|
||||
# function that visualizes the data in the form of a bar chart
|
||||
def visualize():
|
||||
# read the data from the file
|
||||
path = base_path().joinpath("data", "vejaAtrumsFaktiskais.xlsx")
|
||||
data = read_file(path)
|
||||
# create a list of the years
|
||||
years = [year for year in data.keys()]
|
||||
# create a list of the number of movies per year
|
||||
num_movies = [len(data[year]) for year in data.keys()]
|
||||
# create a bar chart
|
||||
plt.bar(years, num_movies)
|
||||
# set the title of the bar chart
|
||||
plt.title("Number of Movies per Year")
|
||||
# set the x-axis label
|
||||
plt.xlabel("Year")
|
||||
# set the y-axis label
|
||||
plt.ylabel("Number of Movies")
|
||||
# show the bar chart
|
||||
plt.show()
|
||||
Loading…
Reference in New Issue
Block a user