4

I have this dataframe:

        timestamp   dttm_utc            value       estimated  anomaly
0       1325376300  2012-01-01 00:05:00  16.9444          0      NaN
1       1325376600  2012-01-01 00:10:00  16.6837          0      NaN
2       1325376900  2012-01-01 00:15:00  16.6837          0      NaN
3       1325377200  2012-01-01 00:20:00  16.9444          0      NaN
4       1325377500  2012-01-01 00:25:00  16.1623          0      NaN
5       1325377800  2012-01-01 00:30:00  16.6837          0      NaN
6       1325378100  2012-01-01 00:35:00  16.1623          0      NaN
7       1325378400  2012-01-01 00:40:00  16.4230          0      NaN
8       1325378700  2012-01-01 00:45:00  16.1623          0      NaN
9       1325379000  2012-01-01 00:50:00  17.2051          0      NaN

How do I change the dttm_utc into ISO8601 format with timezone offset?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 2
    Possible duplicate of [ISO Time (ISO 8601) in Python?](https://stackoverflow.com/questions/2150739/iso-time-iso-8601-in-python) – ApplePie Jun 11 '18 at 23:24

1 Answers1

6

If your object is a datetime object, you can directly convert it to ISO using obj.isoformat(). If your object is not a datetime object, you can convert it using strptime.

Say, if you were using pandas:

my_obj['dttm_iso8601'] = datetime.datetime.strptime(
        my_obj['dttm_utc'],
        '%Y-%m-%s %h:%m:%s'
    ).isoformat()
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ApplePie
  • 8,814
  • 5
  • 39
  • 60