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

  • 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`) – mozway Nov 30 '22 at 07:27
  • read_csv() got an unexpected keyword argument 'format' – Matt - Block-Farms.io Nov 30 '22 at 07:45
  • documentation does not include format as an option, https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html – Matt - Block-Farms.io Nov 30 '22 at 07:45
  • yes, sorry (I mostly answered for the Warning part), you need to pass a function, see [here](https://stackoverflow.com/questions/60349071/how-to-utilise-the-date-parser-parameter-of-pandas-read-csv) and [here](https://stackoverflow.com/questions/28862956/how-to-specify-the-datetime-format-in-read-csv) (I'll add them in the duplicates) – mozway Nov 30 '22 at 07: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! – Matt - Block-Farms.io Nov 30 '22 at 08:11

0 Answers0