Giter Club home page Giter Club logo

Comments (5)

Anurag-Varma avatar Anurag-Varma commented on August 27, 2024 1

Hi @rocodero

You can use the below code to format comma between seconds and milliseconds.

By default Python ISO 8601 Expects a .
But as you have a , you can parse the datetime

from datetime import datetime

# Sample datetime string
datetime_str = "2024-06-17T18:57:43,567"

# Define the format
datetime_format = "%Y-%m-%dT%H:%M:%S,%f"

# Parse the datetime string
parsed_datetime = datetime.strptime(datetime_str, datetime_format)

from pandas.

Anurag-Varma avatar Anurag-Varma commented on August 27, 2024

take

from pandas.

Anurag-Varma avatar Anurag-Varma commented on August 27, 2024

You can also follow this link

And use their suggested similar alternative:

date_string.replace(',', '.'))

from pandas.

rocodero avatar rocodero commented on August 27, 2024

Hi @Anurag-Varma,

thank you for the suggestions, plenty of options there, I know. I was trying to focus on the bug itself and keep it clean, but if workarounds are appreciated I can add them in the future.

What I forgot to add, though: It's only present since pandas 2.2. Version 2.1.4 parses the comma-separated milliseconds without problems.

from pandas.

MarcoGorelli avatar MarcoGorelli commented on August 27, 2024

thanks @rocodero for the report

aside from whether it should parse or not, it looks pretty wild to me that

In [6]: t
Out[6]: Timestamp('2024-06-17 18:57:43.567000')

In [7]: t.unit
Out[7]: 's'

In [8]: t.microsecond
Out[8]: 567000

it records non-zero microseconds but has 's' unit


looks like it's going down the dateutil path

In [9]: pd.to_datetime(['2024-06-17T18:57:43,567']*2)
<ipython-input-9-ad2044f68d63>:1: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.
  pd.to_datetime(['2024-06-17T18:57:43,567']*2)
Out[9]: DatetimeIndex(['2024-06-17 18:57:43', '2024-06-17 18:57:43'], dtype='datetime64[ns]', freq=None)

from pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.