I currently have a function where I am reading in over 25 .csv files. At the moment, I am taking the average over a fixed interval for the same starting and ending sample for each file (see in my code, below).
My goal is now to adjust the starting time to when Temp>50.
My pseudocode is like this:
Current: avg_Temp = df.iloc[63-1:115+1]["Temp"].mean()
Objective: avg_Temp = df.iloc[df[Temp>50]:115+1]["Temp"].mean()
What is the best way to accomplish this?
def plot_data(filename, fig_ax, color):
df = pd.read_csv(f, sep=',',skiprows=24) # Read in the csv.
df.columns=['sample','Time','ms','Temp'] # Set the column names
df=df.astype(str) # Set the data type as a string.
df["Temp"] = df["Temp"].str.replace('\+ ', '').str.replace(' ', '').astype(float) # Convert to float
# Take the average of the data from the Temp column, starting from sample 63 until sample 115.
avg_Temp = df.iloc[63-1:115+1]["Temp"].mean()

df.loc[df['temp']>50, 'Temp'].head(50).mean(0)?