#๐ Convert Column of String Dates to Numpy Array of Floats Using Vectorization
16 messages ยท Page 1 of 1 (latest)
@worthy sigil
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
!docs pandas.to_datetime
pandas.to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, utc=False, format=None, exact=_NoDefault.no_default, unit=None, ...)```
Convert argument to datetime.
This function converts a scalar, array-like, [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) or [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame)/dict-like to a pandas datetime object.
@worthy sigil start with this
Then you need to decide what you want 1 to be (a second, a minute, etc.)
This should help you https://stackoverflow.com/questions/54312802/pandas-convert-from-datetime-to-integer-timestamp
oh thanks
Ignore anything you see about using apply. That won't be vectorized
Is this the right idea?
queued_time_col = pd.to_datetime(df['Original Time Queued'].str[11:20], format='%H:%M:%S %p', exact=True)
ValueError: time data "03:04:47 " doesn't match format "%H:%M:%S %p", at position 0.
Changed slice [11:20] to [11:22]:
queued_time_col = pd.to_datetime(df['Original Time Queued'].str[11:22], format='%H:%M:%S %p', exact=True)
Works now
!solved
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.