1

I'm trying to merge two datasets through a datetime field. I'm having trouble getting them in the same format.

First dataset has 2 fields, date and hour. Hour needs to be converted from Pacific time to UTC. Date needs to be converted from DDMMYYYY to YYYYMMDD. Then I'd like to merge them into a datetime field. I've grabbed them through an API that writes to a Pandas dataframe.

Second dataset is a csv and has everything I need to merge in one UTC datetime field as a string.

This is my first time using Pandas, and it looks to me like strptime and similar functions are not designed to be used with a Pandas dataframe. Am I correct in thinking this? Please explain to me like I only have a few months experience programming (because this is true).

So far, the following code seems to work on the first dataset, but it doesn't have the correct hour input for matching to UTC.

pd.to_datetime(results_df['date'] + " " + results_df['hour'], infer_datetime_format=True)  

  • It would be helpful to see sample data to understand your problem better. See [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). There is a whole [section in the pandas docs about datetimes](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html) but it's not entirely clear what your inputs and expected outputs are. – G. Anderson Oct 14 '19 at 19:23
  • Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – Gonçalo Peres Sep 07 '22 at 11:32

0 Answers0