Skip to content

Commit

Permalink
temperature format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozodbek47 committed Jan 21, 2024
1 parent cdcdeec commit 2d96f13
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions exercises/exercise4.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
z_ref.extract(csv_file_name, '.')

# Reshaping the data
df = pd.read_csv(csv_file_name, delimiter=';', usecols=range(12), decimal=",")
df = pd.read_csv(csv_file_name, delimiter=';', usecols=range(12))

selected_columns = ["Geraet", "Hersteller", "Model", "Monat", "Temperatur in °C (DWD)", "Batterietemperatur in °C", "Geraet aktiv"]
df = df[selected_columns]
df = df.rename(columns={"Temperatur in °C (DWD)": "Temperatur", "Batterietemperatur in °C": "Batterietemperatur"})

# Transforming the data
df["Temperatur"] = (df["Temperatur"] * 9/5) + 32
df["Batterietemperatur"] = (df["Batterietemperatur"] * 9/5) + 32
temperature_columns = ["Temperatur", "Batterietemperatur"]

for column in temperature_columns:
df[column] = df[column].apply(lambda x: float(x.replace(',', '.')) if pd.notna(x) else pd.NA)
df[column] = (df[column] * 9/5) + 32

# Validating the data
df = df[df["Geraet"] > 0]
Expand Down

0 comments on commit 2d96f13

Please sign in to comment.