0

I am currently working on multiple datasets with TimeStamp column : dd/mm/yyyy HH:MM daily data at 5 mins interval i want to resample dataset to fill missing dates n timestamps

Issue is few datasets have some rows as ddmmyy and then format abruptly changes to mmddyyyy after say first few 100 rows and again ddmmyy without any pattern...

need solution or help to correct this issue

code i am using :::

df['Timestamp'] = pd.to_datetime(df['Timestamp'])
df['Timestamp'] = df.Timestamp.dt.strftime('%d/%m/%y %H:%M')
df['Timestamp'] = pd.to_datetime(df['Timestamp'])


start_dt = df.loc[0, "Timestamp"]
end_dt = df["Timestamp"].iloc[-1]
r = pd.date_range(start=start_dt, end=end_dt, freq="5min")
# Reindexing by adding missing dates


df = df.set_index('Timestamp').reindex(r).rename_axis("Timestamp").reset_index()
  • Look at the `dateutil` module. `from dateutil import parser` will give you a function `parser.parse` that will take those formats in its stride. There are some things it can't handle without assistance, for example is 01/02/2021 the first of February or the second of January? But if the timestamps are sorted then you can tell the difference. – BoarGules Oct 13 '21 at 15:49
  • Does this answer your question? [Pandas: Datetime Improperly selecting day as month from date](https://stackoverflow.com/questions/69255327/pandas-datetime-improperly-selecting-day-as-month-from-date) – FObersteiner Oct 13 '21 at 18:20

1 Answers1

-1

Use regex to filter rows having ddmmyy & mmddyy and then convert to datetime format.

  • Hi, try to show some solutions code to be more helpful. – Diesan Romero Oct 28 '21 at 19:42
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Diesan Romero Oct 28 '21 at 19:43