Reputation: 3
i have one big dataframe as a .csv, which is updated over time.
I take the last 7 rows of this dataframe and search for a startpoint and an endpoint. To make sure, the startpoint i'm using is earlier, than the endpoint within this shortened dataframe, i would like to compare the two timestamps.
The problem is, i can only get them as a series object, which i can't compare via <
or >
Is there a possibility to compare the two values?
import pandas as pd
import datetime
df = pd.read_csv(r'\Dataframe.csv')
df_tail = df.tail(10)
Start = df_tail.loc[(df['node']=='ns=4;i=560') & (df['Value;']==3)]['Timestamp']
Stop = df_tail.loc[df['node']=='ns=2;s=DistanceAbs']['Timestamp']
Start_df = (Start.to_frame()).reset_index(drop=True)
Stop_df = (Stop.to_frame()).reset_index(drop=True)
Start = Start_df["Timestamp"]
if Start_df["Timestamp"] < Stop_df["Timestamp"]:
print('yes')
The shortend dataframe looks like this:
Timestamp node Value;
63 2020-12-16 12:03:07.831569 ns=4;i=560 1.0
64 2020-12-16 12:03:10.567988 ns=2;s=DistanceAbs 0.8871407871551859
65 2020-12-16 12:03:12.832312 ns=4;i=562 440.0
66 2020-12-16 12:03:13.831145 ns=4;i=560 2.0
67 2020-12-16 12:03:20.331216 ns=4;i=560 3.0
68 2020-12-16 12:03:27.330800 ns=4;i=560 0.0
69 2020-12-16 12:03:32.833464 ns=4;i=560 1.0
Upvotes: 0
Views: 85
Reputation: 36
You can get the value of the first item of the Series with the item()
method:
Start = df_tail.loc[(df['node']=='ns=4;i=560') & (df['Value;']==3)]['Timestamp'].item()
Stop = df_tail.loc[df['node']=='ns=2;s=DistanceAbs']['Timestamp'].item()
You can then check you condition:
if Start < Stop:
print('yes')
Upvotes: 1