Previous answers don't help me because I'm looping through dataframes, where the columns change each loop so referencing a specific column df["col"] doesn't work.
I have a large DataFrame that's just a more complicated version of:
data = [[1, 2, 3, 4, 5], [10, 20, 30, 40, 50], [100, 200, 300, 400, 500]]
df1 = pd.DataFrame(data, columns = ['Time(s)', 'Cell1', 'Cell2'])
I then loop through the cells, which change each time I run the code:
for cell in df1.columns[2:]:
*do a bunch of stuff looping through other dataframes*
I end up with two variables, timelower and timeupper, I want every row (inclusive) between these two times into a new dataframe, where the new dataframe has the same columns but the new times between timelower and timeupper.
The desired output is a new dataframe, df2, with the same columns as df1 but only specific rows between timelower and timeupper in df1.