day2 intermediate code3
This commit is contained in:
parent
331e55f987
commit
cd616d9a97
@ -34,12 +34,44 @@ daily = beverages_by_date.resample("8h").bfill()
|
||||
print(daily.loc["2024-02-8":"2024-02-14"])
|
||||
|
||||
# übung mit zeiten
|
||||
solar_df = pd.read_csv("../data/Balkonkraftwerk.csv", index_col=0)
|
||||
solar_df = pd.read_csv("../data/Balkonkraftwerk.csv",
|
||||
index_col=0)
|
||||
solar_df.index = pd.to_datetime(solar_df.index)
|
||||
print(solar_df)
|
||||
print(solar_df.columns)
|
||||
|
||||
# 1) Wie sieht es im durchschnitt jeden Tag aus (D)
|
||||
# 2) An welchen Tagen war die effizientz > 35%
|
||||
print(solar_df.index)
|
||||
|
||||
# 1) Wie sieht es im Durchschnitt jeden Tag aus (D)
|
||||
daily = solar_df.resample("d").mean()
|
||||
print(daily)
|
||||
print(daily[daily["efficiency_percent"] > 37])
|
||||
# 2) An welchen Tagen war die durchschnittliche effizientz > 35%
|
||||
# 2) maximum > 70%
|
||||
# 3) Stündliche Werte interpolieren (h) (1h), (3h)
|
||||
|
||||
hourly = solar_df.resample("h").ffill()
|
||||
print(hourly)
|
||||
|
||||
# - Komisch
|
||||
|
||||
print(hourly.loc["2024-05-02"])
|
||||
|
||||
print()
|
||||
daily = beverages_by_date.resample("8h").bfill()
|
||||
print(daily.loc["2024-02-8":"2024-02-14"])
|
||||
|
||||
values = pd.DataFrame({
|
||||
"times": ["2025-08-01 05:00:00", "2025-08-01 09:00:00", "2025-08-01 11:00:00"],
|
||||
"values": [1, 2, 10]
|
||||
})
|
||||
values.set_index("times", inplace=True)
|
||||
values.index = pd.to_datetime(values.index)
|
||||
print("-"*100)
|
||||
print(values)
|
||||
values = values.resample("h").interpolate()
|
||||
print(values)
|
||||
values.index = values.index.tz_localize('Europe/Berlin')
|
||||
print(values)
|
||||
values.index = values.index.tz_convert("Us/Central")
|
||||
print(values)
|
||||
|
||||
25
src/T13_GroupbyExtra.py
Normal file
25
src/T13_GroupbyExtra.py
Normal file
@ -0,0 +1,25 @@
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
names = ('Ortwin', 'Mara', 'Siegrun', 'Sylvester', 'Metin', 'Adeline', 'Utz', 'Susan', 'Gisbert', 'Senol')
|
||||
data = {'Monday': np.array([0, 9, 2, 3, 7, 3, 9, 2, 4, 9]),
|
||||
'Tuesday': np.array([2, 6, 3, 3, 5, 5, 7, 7, 1, 0]),
|
||||
'Wednesday': np.array([6, 1, 1, 9, 4, 0, 8, 6, 8, 8]),
|
||||
'Thursday': np.array([1, 8, 6, 9, 9, 4, 1, 7, 3, 2]),
|
||||
'Friday': np.array([3, 5, 6, 6, 5, 2, 2, 4, 6, 5]),
|
||||
'Saturday': np.array([8, 4, 8, 2, 3, 9, 3, 4, 9, 7]),
|
||||
'Sunday': np.array([0, 8, 7, 8, 9, 7, 2, 0, 5, 2])}
|
||||
|
||||
# T property für .transpose()
|
||||
data_df = pd.DataFrame(data, index=names).transpose() # achtung hier wird transponiert (spalten zu zeilen und zeilen zu spalten)
|
||||
print(data_df)
|
||||
|
||||
def categorize_day(day):
|
||||
if day in {"Saturday", "Sunday"}:
|
||||
return "Weekend"
|
||||
return "Weekday"
|
||||
|
||||
# die spalte nach welcher gruppiert wird in diesem Fall auf den Index gesetzt wird
|
||||
res = data_df.groupby(categorize_day).sum()
|
||||
print(res)
|
||||
|
||||
70
src/T14_Plotten.py
Normal file
70
src/T14_Plotten.py
Normal file
@ -0,0 +1,70 @@
|
||||
# ältere Bibliothek
|
||||
# - statische Plots
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
|
||||
# interaktion
|
||||
# import plotly
|
||||
|
||||
|
||||
# plotten direkt von pandas
|
||||
# -> backend: matplotlib
|
||||
|
||||
|
||||
cities = {"Stadt": ["London", "Berlin", "Madrid", "Rom",
|
||||
"Paris", "Wien", "Bukarest", "Hamburg",
|
||||
"Budapest", "Warsaw", "Barcelona",
|
||||
"München", "Mailand"],
|
||||
"Population": [8615246, 3562166, 3165235, 2874038,
|
||||
2273305, 1805681, 1803425, 1760433,
|
||||
1754000, 1740119, 1602386, 1493900,
|
||||
1350680],
|
||||
"Land": ["England", "Deutschland", "Spanien", "Italien",
|
||||
"Frankreich", "Österreich", "Romanien",
|
||||
"Deutschland", "Ungarn", "Polen", "Spanien",
|
||||
"Deutschland", "Italien"]}
|
||||
|
||||
areas = [1572, 892, 604, 1285, 105,415, 228, 755, 525, 517, 101, 310, 182]
|
||||
cities_df = pd.DataFrame(cities)
|
||||
cities_df["Flaeche"] = areas
|
||||
print(cities_df)
|
||||
|
||||
#cities_df.plot(x="Stadt", y=["Population", "Flaeche"])
|
||||
#plt.xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)
|
||||
#plt.show()
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
cities_df.plot(x="Stadt", y=["Population", "Flaeche"], ax=ax)
|
||||
ax.set_xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)
|
||||
fig.suptitle("Area und Flaeche in einem")
|
||||
|
||||
fig, ax = plt.subplots(2, 1, sharex=True) # ax ein array mit 2 elementen
|
||||
cities_df.plot(x="Stadt", y="Population", ax=ax[0])
|
||||
cities_df.plot(x="Stadt", y="Flaeche", ax=ax[1])
|
||||
fig.suptitle("2 axes in einer figure")
|
||||
for i in range(2):
|
||||
ax[i].set_xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
area_axes = ax.twinx()
|
||||
|
||||
width = 0.35
|
||||
|
||||
x_pos = range(len(cities_df)) # 0, 1, 2, ..., 12
|
||||
ax.bar([x - width/2 for x in x_pos], cities_df["Population"], width=width, color="blue", label="Population")
|
||||
area_axes.bar([x + width/2 for x in x_pos], cities_df["Flaeche"], width=width, color="orange", label="Flaeche")
|
||||
|
||||
ax.set_xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)
|
||||
fig.suptitle("Area und Flaeche in einem")
|
||||
handles1, labels1 = ax.get_legend_handles_labels()
|
||||
handles2, labels2 = area_axes.get_legend_handles_labels()
|
||||
|
||||
ax.legend(handles1 + handles2, labels1 + labels2)
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
12
src/T15_EnergyPlots.py
Normal file
12
src/T15_EnergyPlots.py
Normal file
@ -0,0 +1,12 @@
|
||||
# 1. Energie nach Quartal
|
||||
# alle energieformen in einen plot
|
||||
|
||||
# 2. In 2 Plots übereinander
|
||||
# - greenenergies
|
||||
# - nongreenenergies
|
||||
|
||||
|
||||
# 3. Alle energien nach type in einem barplot
|
||||
# - pie-plot
|
||||
|
||||
# df.plot.pie
|
||||
Loading…
Reference in New Issue
Block a user