Skip to content
Advertisement

DataFrame contains a column of dates which are having these types: “‘5-15-2019′” and 05152021.I want to extract pattern of it

DataFrame contains dates which are having these types: “21-10-2021” and 29052021.I want to extract pattern of it. for example ‘5-15-2019’,it needs to produce ‘%d-%m-%Y’ ‘05152021’ it needs to produce ‘%d%m%Y’

i tried in this way:

JavaScript

output: i got a list of those patterns.i need to get pattern ‘%d-%m-%Y’ and Similarly i need to get pattern for ‘%d%m%Y’ also.how i need to do it? can any body help me.Thank you

Advertisement

Answer

You can use the internal pandas method pandas._libs.tslibs.parsing.guess_datetime_format. Be careful, this is not part of the public API, so the function might change without any warning in the future.

option 1
JavaScript
option 2

....YYYY dates are not supported. For those you need to cheat by adding dashes temporarily:

JavaScript

Example:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement