Excel does not support datetimes with timezones

amandeep179018
I'm getting this error which occurs when I want to transfer live data into excel.
the complete error is :
Excel does not support datetimes with timezones. Please ensure that datetimes are timezone unaware before writing to Excel.
Please, can someone tell me how to fix it.
  • rakeshr
    @amandeep179018
    Excel does not support datetimes with timezones. Please ensure that datetimes are timezone unaware before writing to Excel.
    As the error states, you need to remove timezone from the timestamp field before dumping it to an excel file.You can try something as below to remove timezone from timestamp and then dump to excel.
    dt = datetime_withtimezone.replace(tzinfo=None)
  • amandeep179018
    amandeep179018 edited December 2019
    token=55016711
    to_date=datetime.now()
    from_date=to_date- timedelta(days=5)
    interval="5minute"

    records = kite.historical_data(token, from_date, to_date, interval)
    df = pd.DataFrame(records)
    df.to_excel("CRUDEOILM19DECFUT.xlsx")
    pdb.set_trace()


    I have tried to apply this code (dt = datetime_withtimezone.replace(tzinfo=None)) but it didn't work please tell me what should I do

    please edit this code and tell me what have I done wrong I'm stuck on this for 2 days.
    thanks
  • rakeshr
    @amandeep179018
    df = pd.DataFrame(records)
    You can dump column wise data instead of direct dump.
    Are you trying to stream WebSocket data to Excel?
    Instead, you can try using Kite XL(3rd party library).
  • amandeep179018
    Thanks, it worked.
This discussion has been closed.