!rm -rf transformed_data_eager
import os
import time
import random
import pandas as pd
os.mkdir("transformed_data_eager")
def read_a_file(filename):
time.sleep(random.random())
df = pd.read_csv(f"data/{filename}", parse_dates=["timestamp"], index_col="timestamp")
return df
def do_a_transformation(df):
time.sleep(random.random())
df["temperature_F"] = df["temperature"] * 9/5 + 32
return df
def write_it_back_out(df, filename):
time.sleep(random.random())
path = f"transformed_data_eager/{filename}"
df.to_csv(path)
return path
filenames = os.listdir("data")
outputs = []
for filename in filenames:
df = read_a_file(filename)
df = do_a_transformation(df)
path = write_it_back_out(df, filename)
outputs.append(path)
outputs
['transformed_data_eager/4.part', 'transformed_data_eager/2.part', 'transformed_data_eager/5.part', 'transformed_data_eager/1.part', 'transformed_data_eager/7.part', 'transformed_data_eager/8.part', 'transformed_data_eager/3.part', 'transformed_data_eager/0.part', 'transformed_data_eager/6.part']