LoginSignup
0
0

More than 1 year has passed since last update.

松山市の石手川ダム貯水率の変化(年間)のCSVから個々の貯水率と比較グラフ作成

Posted at

import pandas as pd

url = "https://www.matsuyama-waterworks.jp/water/data/data.csv"

df0 = pd.read_csv(
    url,
    encoding="cp932",
    header=None,
    index_col=[0, 1],
)

df0

df0.iloc[1] = df0.iloc[1].replace({"平成6年度": 1994, "令和3年度": 2021, "令和4年度": 2022})
col = df0.iloc[:2].fillna(method="ffill", axis=1).values
df0.columns = pd.MultiIndex.from_arrays(col)
df0.index.names = ["month", "day"]

df1 = df0.iloc[2:].copy()
df1

# 貯水率

df2 = df1.loc[:, "石手川ダム貯水率[%]"].astype(float)
df2.columns.name = "year"
df2["date"] = df2.index.map(lambda x: "{0[0]:02}/{0[1]:02}".format(list(map(int, x))))

df2
import plotly.express as px

fig_wsr = px.line(df2, x="date", y=[1994, 2021, 2022], width=1200, height=500)
fig_wsr.show()

fig_wsr.write_image("dam.png")

newplot(16).png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0