0

I am receiving the following warning:

UserWarning: Parsing dates in DD/MM/YYYY format when dayfirst=False (the default) was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
  df = pd.read_csv(filename), parse_dates=['DateTime'], dayfirst=False)

My code:

df = pd.read_csv(filename, parse_dates=['DateTime'], dayfirst=False)
df['DateTime'] = df['DateTime'].apply(lambda x: datetime.strptime(str(x), '%Y-%m-%d %H:%M:%S').strftime('%d-%m-%Y'))
eod_quote = df.iloc[df.index[df['DateTime'].astype(str) == '{}'.format(current_date)].values.astype(int)[0]]['{}{}'.format(ticker,quote_asset)]

My csv contents when imported into panda DF:

       UnixTimestamp DateTime    ETHUSD
    0  1649053626.0  04-04-2022  3521.58
    1  ...           ...         ...

How do I change my code or the way I save or access the .csv file to not receive the associated warning?

I have tried the following, but eod_quote errors out, not able to find all the associated dates, and I believe this is how python is viewing the datetime format as the datetime and quote price exists within the .csv file

5
  • This is a Warning, non an Error, this doesn't mean you did something wrong but just informs you. See the duplicate for how to silence it (or provide the explicit format: format='%d/%m/%Y' instead of dayfirst=False) Commented Nov 30, 2022 at 7:27
  • read_csv() got an unexpected keyword argument 'format' Commented Nov 30, 2022 at 7:45
  • documentation does not include format as an option, pandas.pydata.org/pandas-docs/stable/reference/api/… Commented Nov 30, 2022 at 7:45
  • yes, sorry (I mostly answered for the Warning part), you need to pass a function, see here and here (I'll add them in the duplicates) Commented Nov 30, 2022 at 7:50
  • Ah I see, Ill try pass it as a function. I didn't want to silence the warning as I just want to not generate the warning at all. Thanks! Commented Nov 30, 2022 at 8:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.