Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas not seeing data as datetime

Panda is not picking up date time (ie, I need to keep minutes and seconds), nor can I convert it.

    import pandas as pd

    rides = pd.read_parquet('../data/raw/rides_2022-01.parquet')

    rides.head(20)

    rides = rides[['pickup_datetime', 'PULocationID']]

    rides.rename(columns={
        'tpep_pickup_datetime': 'pickup_datetime',
        'PULocationID': 'pickup_location_id',
    }, inplace=True)

     rides.to_datetime(rides['pickup_datetime'])  <-- errors here AttributeError: 'DataFrame' object has no attribute 'to_datetime'

    rides['pickup_datetime'].describe(include='all')

        count                          2463879
        mean     2022-01-17 01:58:40.393673472
        min                2022-01-01 00:00:08
        25%                2022-01-09 15:37:56
        50%                2022-01-17 12:11:54
        75%                2022-01-24 13:49:37
        max                2022-01-31 23:59:58
        Name: pickup_datetime, dtype: object

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is the correct syntax

rides["pickup_datetime"] = pd.to_datetime(rides["pickup_datetime"])
rides.dtypes

Output:

pickup_datetime    datetime64[ns]
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading