Mar-17-2022, 01:53 PM
@snippsat can i ask why have the mask using 2 dates?
Also just to be clear, i can add "columns" by adding a dataframe after reading in the file like below? and if i want 2 columns, i can just define it below this one and it will add both to the end of the file columns correct?
So i implemented the suggestions above.. but getting an error:
Figured it out.. because i had left this line in place, it was causing the issue
mask = (df['DateTime'] > '2022-03-08 16:06:00') & (df['DateTime'] >= '2022-03-08 16:15:00')Ill be trying both suggestions above shortly after my meeting, so thank you again for the suggestions..
Also just to be clear, i can add "columns" by adding a dataframe after reading in the file like below? and if i want 2 columns, i can just define it below this one and it will add both to the end of the file columns correct?
df["DateTime"] = df["Date"] + df["Time"]
So i implemented the suggestions above.. but getting an error:
import pandas as pd from io import StringIO df = pd.read_csv(StringIO("Dates.txt"), sep=",", names=["Date", "Time", "Comment"]) df['Date'] = pd.to_datetime(df['Date']) df['DateTime'] = pd.to_datetime(df["Date"] + df["Time"]) mask = (df['DateTime'] > '2022-03-08 15:18:00') df_new = df.loc[mask] df_new = df_new.drop(columns=['DateTime']) print(df_new)
Error:ParserError: Too many columns specified: expected 3 and found 1
Figured it out.. because i had left this line in place, it was causing the issue
df['Date'] = pd.to_datetime(df['Date'])removed it and runs and works like a charm, thank you so much for all the suggestions and help.