Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I have a table with 8 columns and 40,000 rows, the following table (DF700) is a small section of the entire table. I need to split the 'sdk_ts' column so that the date and time are separate and the 'UTC' is removed from all rows.

            sdk_ts                                                   y           z 

0   2019-07-02 00:12:32 UTC                  3.455   4.555

1   2019-07-02 00:12:32 UTC                  4.567   6.897

2   2019-07-02 00:12:32 UTC                  9.304   0.440    : : : 

3   2019-07-02 00:12:59.6 UTC               8.909   0.405

4   2019-07-02 00:12:34.789 UTC           10.30   2.344

                               

I've attempted the following code:

DF800 = DF700['sdk_ts'].str.split(n=1, expand=True)

However, the result is:

              0                         1

0   2019-07-02      00:12:32 UTC

1   2019-07-02      00:12:32 UTC

2   2019-07-02     00:12:32 UTC

3   2019-07-02     00:12:59.6 UTC

4   2019-07-02     00:12:34.789 UTC

5   2019-07-02     00:12:35.048 UTCa

Is there another way I can achieve this goal? Splitting the date and time, getting rid of 'UTC' in all rows and making sure that the other columns are still on the table.

1 Answer

0 votes
by (41.4k points)

Convert  'sdk_ts' column to datetime format to extract date and time from it.

Here is the code:

df['sdk_ts'] = pd.to_datetime(df['sdk_ts'])

df['date'] = df['sdk_ts'].dt.date

df['time'] = df['sdk_ts'].dt.time

You can refer to our Python online course for more information. 

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers

500 comments

108k users

Browse Categories

...