-1

Property to store most recent won deal stores information in rather odd format. The data is in datetime format with different timezones.

I'm getting the following errors:

"If tzaware, these values represent unix timestamps, so we" and "ValueError: Array must be all same time zone"

When I try one of the following commands:

pd.to_datetime(df1['properties__recent_deal_close_date__value'])

and

df1['properties__recent_deal_close_date__value'].dt.tz_convert('Eruope/Berlin')

I would like to convert data such as this:

2018-11-16 11:32:51.285000+01:00    
2019-02-28 17:13:49.492000+01:00    
2018-08-29 09:50:51+02:00   

To this:

2019-11-16
2019-02-28
2018-08-29
Tajs
  • 521
  • 7
  • 18

1 Answers1

0

Using dparser:

import dateutil.parser as dparser

dt_1 = "2018-11-16 11:32:51.285000+01:00"
dt_2 = "2019-02-28 17:13:49.492000+01:00"
dt_3 = "2018-08-29 09:50:51+02:00"

print("Date: {}".format(dparser.parse(dt_1,fuzzy=True).date()))
print("Date: {}".format(dparser.parse(dt_2,fuzzy=True).date()))
print("Date: {}".format(dparser.parse(dt_3,fuzzy=True).date()))

OUTPUT:

Date: 2018-11-16
Date: 2019-02-28
Date: 2018-08-29
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
  • Thanks! I just need to figure it out how to iterate through all the rows. – Tajs Apr 11 '19 at 09:50
  • @MatijaŽiberna `for index, row in df.iterrows():`? – DirtyBit Apr 11 '19 at 09:51
  • `for index, row in df1.iterrows(): row['properties__recent_deal_close_date__value'] = dparser.parse(row,fuzzy=True).date()` This is what I've tried. I've received the following error: `TypeError: Parser must be a string or character stream, not Series` – Tajs Apr 11 '19 at 10:00
  • Try: `for index, row in df1.iterrows(): print(dparser.parse(row['properties__recent_deal_close_date__value'],fuzzy=True).date())` – DirtyBit Apr 11 '19 at 10:02
  • Thanks, but still same error persists: `TypeError: Parser must be a string or character stream, not datetime` – Tajs Apr 11 '19 at 10:12
  • 1
    That is a different error, just convert it to string: `for index, row in df1.iterrows(): print(dparser.parse(str(row['properties__recent_deal_close_date__value']),fuzzy=True).date())` – DirtyBit Apr 11 '19 at 10:13
  • Got answer here: https://stackoverflow.com/questions/25478528/updating-value-in-iterrow-for-pandas – Tajs Apr 11 '19 at 11:03