Files
DHGeography/ratios.py
2023-10-17 18:31:03 +03:00

33 lines
951 B
Python

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# Read the CSV file into a Pandas DataFrame
file_path = "texts_by_period_and_location_saparated_by_periods_in_columns.csv"
df = pd.read_csv(file_path)
# Define the columns to summarize
columns_to_summarize = ["ancient", "old", "middle", "new", "late"]
# Group the data by the "place" column and calculate sums within each group
grouped = df.groupby("place")[columns_to_summarize].sum().reset_index()
# Create a bar chart using Plotly
fig = go.Figure()
# Add a bar trace for each category
for col in columns_to_summarize:
fig.add_trace(go.Bar(x=grouped["place"], y=grouped[col], name=col))
# Customize the layout
fig.update_layout(
title="Summary of Categories by Place with Filtering",
xaxis_title="Place",
yaxis_title="Total Count",
xaxis=dict(categoryorder='total descending'),
barmode='group'
)
# Show the interactive graph
fig.show()