Epoch Datetime Conversion

64 Views Asked by At

I have this raw Data. An excerpt of the raw data was:

data2 = """
|--------------------------------------------------|
| Stored images:                   |
|--------------------------------------------------|
| ID    | Date      | Size      | Status   |
|--------------------------------------------------|
| 398   | 1644811303    | 2517210   | 1    |

| 398   | 1644811294    | 2517210   | 0    |

| 398   | 1644811286    | 2517210   | 0    |

| 398   | 1644811278    | 2517210   | 0    |

| 14    | 1595876465    | 10068714  | 0    |

| 13    | 1595790065    | 10068714  | 1    |

| 12    | 1595703665    | 10068714  | 0    |

| 11    | 1595617265    | 10068714  | 0    |

| 10    | 1595530865    | 10068714  | 1    |

After conversion into Pandas, and the following columns conversions:

df["ID"] = pd.to_numeric(df["ID"])
df['Date'] = pd.to_datetime(pd.to_numeric(df['Date'], errors='coerce'), unit='s')

produced the underneath DataFrame result.

|    | ID  | Date                | Size     | Status |
|----|-----|---------------------|----------|--------|
| 0  | 398 | 2022-02-14 04:01:43 | 2517210  | 1      |
| 1  | 398 | 2022-02-14 04:01:34 | 2517210  | 0      |
| 2  | 398 | 2022-02-14 04:01:26 | 2517210  | 0      |
| 3  | 398 | 2022-02-14 04:01:18 | 2517210  | 0      |
| 4  | 14  | 2020-07-27 19:01:05 | 10068714 | 0      |
| 5  | 13  | 2020-07-26 19:01:05 | 10068714 | 1      |
| 6  | 12  | 2020-07-25 19:01:05 | 10068714 | 0      |
| 7  | 11  | 2020-07-24 19:01:05 | 10068714 | 0      |
| 8  | 10  | 2020-07-23 19:01:05 | 10068714 | 1      |
| 9  | 9   | 2020-07-22 19:01:27 | 10068714 | 1      |
| 10 | 8   | 2020-07-21 19:01:06 | 10068714 | 1      |
| 11 | 7   | 2020-07-20 19:01:05 | 10068714 | 1      |
| 12 | 6   | 2020-07-19 19:01:27 | 10068714 | 1      |
| 13 | 5   | 2020-07-18 19:01:20 | 10068714 | 1      |
| 14 | 4   | 2020-07-17 19:01:27 | 10068714 | 1      |
| 15 | 3   | 2020-07-17 12:01:21 | 10068714 | 1      |

My challenge is if a print the min and max dates, i get 2022-02-14 04:01:43 as the maximum date and I get 2020-07-08 07:38:36 as the minimum date. I expexted the minimum date to be rather 2022-02-14 04:01:43 and the maximum date to be 2020-07-08 07:38:36. These are the data types I get

ID                 int64
Date      datetime64[ns]
Size               int64
Status  

Am i missing something? A help will be appreciated

I tried to print max and min dates using print(df['Date'].max(), df['Date'].min())

I expect 2020-07-08 07:38:36 2022-02-14 04:01:43 to get but I get 2022-02-14 04:01:43 2020-07-08 07:38:36

0

There are 0 best solutions below