I imported a worksheet from a google sheets which happens to have a timestamp in string format in the ['Timestamp'] column. To filter the date by comparison and select some rows, I've created a variable which takes today's date (diaHoy) and another which is from the day before (diaAyer)
Then I'm trying to apply a mask which compares diaHoy and diaAyer with each timestamp element, but I can't because diaHoy and diaAyer are datetime elements and each timestamp cell is a string. I've tried applying strptime to ['Timestamp'] column but i can't because it's a list
Sample data:
df = pd.DataFrame ({'16/10/2019 14:56:36':['A','B'],'21/10/2019 14:56:36':['C','D'],'21/10/2019 14:56:36':['E','F']
diaHoy = 2019/10/21
diaAyer = 2019/10/20
import pandas as pd
diaHoy = datetime.today().date()
diaAyer = diaHoy + timedelta(days = -1)
wks1 = gc.open_by_url("CODE_URL").sheet1
df1 = wks1.get_all_values()
df1.pop(0)
mask1 = (df1 > diaAyer) & (df1 <= diaHoy)
pegado1 = df1.loc[mask1]
I expect that the mask filters out rows by the dates in the first column, by comparing them with diaHoy and diaAyer
Filter: between 21/10/2019 and 20/10/2019
Expected result:
df = pd.DataFrame ({'21/10/2019 14:56:36':['C','D'],'21/10/2019 14:56:36':['E','F']
you can convert the tuple of timestamp strings to a list of datetime objects:
import pandas as pd
df2 = pd.DataFrame({pd.to_datetime(key):df[key] for key in df})