0

I want to separate these column into two, since Excel extract function just takes way too much I figured I could do it in Python with Jupyter Notebook, using Pandas. But I haven't really do this before, normally I would have data already treated so I am having difficulties.

I tried using excel but it takes forever.

+---------------------+----------------------+-----------------+
|        date + hour  |        date only     |    hour only    |
+---------------------+----------------------+-----------------+
| 01/01/19 01         | 01/01/2019 (formated)|   1 (number)    |
+---------------------+----------------------+-----------------+


+---------------------+----------------------+-----------------+
|        date + hour  |        date only     |    hour only    |
+---------------------+----------------------+-----------------+
| 01/01/19 01         | 01/01/2019 (formated)|   1 (number)    |
+---------------------+----------------------+-----------------+
  • 2
    ```df['date+hour'].str.split(' ', expand = True)``` You can split it on the space, then expand it to new columns, which you can then rename. – Ben Pap Jul 17 '19 at 21:17

1 Answers1

0

I think the discussion here will help a lot: How to split a column into two columns?

Basically, you want to use pandas.Series.str.split (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.split.html) to split the string in your Date & Hour column into a list and then assign the two halves of that list into new columns.

JDenman6
  • 329
  • 2
  • 8