Python Pandas split Date in day month year and hour
Steve
Gronicus at SGA.Ninja
Wed Aug 19 16:38:33 EDT 2020
0 2017-11-01 00:00:00
If you are reading it is as a line into python, then it is a tuple and can be parsed accordingly:
Nb = YourdataLIne[0:1] #Line Number
Yr = YourDataLine[3:7] #Year
Da = YourDataLine[9:11] #Day
Mo = YourDataLine[13:14] #Month
Hr = YourDataLine[16:18] #hour
Mn = YourDataLine[20:21] #minute
Sc = YourDataLine[22:23] #second
Use
Print ("Year = " + Yr + ", Month = " + Mo + ", Day = " + Da + ", Hour = " + Hr)
You may have to adjust the numbers depending on how the line is read.
Is that what you want?
FootNote:
If money does not grow on trees, then why do banks have branches?
-----Original Message-----
From: Python-list <python-list-bounces+gronicus=sga.ninja at python.org> On Behalf Of Brian Oney via Python-list
Sent: Wednesday, August 19, 2020 2:01 PM
To: python-list at python.org
Subject: Re: Python Pandas split Date in day month year and hour
On August 19, 2020 7:32:45 PM GMT+02:00, J Conrado <jorge.conforte at inpe.br> wrote:
>
>
>Hi,
>
>
>I'm satarting using Pandas to read excel. I have a meteorological
>synoptic data and I have for date:
>
>
>0 2017-11-01 00:00:00
>1 2017-11-01 03:00:00
>2 2017-11-01 06:00:00
>3 2017-11-01 09:00:00
>4 2017-11-01 12:00:00
>.. ...
>229 2017-11-30 09:00:00
>230 2017-11-30 12:00:00
>231 2017-11-30 15:00:00
>232 2017-11-30 18:00:00
>233 2017-11-30 21:00:00
>
>
>I would like know how can I get for this array the values for day,
>month and hour:
>
>2017-11-01 03:00:00 year = 2017 month = 11 day = 1 and
> hour = 3
>
>From the hip, I would use the strptime function (in the time module?)
time.strptime(string_value, '%F %T')
If I recall correctly, the doc for the specific strings is in the strptime function's doc.
This is just a starting point. Good luck!
HTH
--
https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list