Learn Python 3.7 by building applications by Philipp Kats

Learn Python 3.7 by building applications by Philipp Kats

Author:Philipp Kats [Philipp Kats]
Language: eng
Format: epub, mobi
Tags: COM000000 - COMPUTERS / General, COM082000 - COMPUTERS / Bioinformatics, COM006000 - COMPUTERS / Buyer
Publisher: Packt
Published: 2019-08-30T13:00:38+00:00


Time

Another column is time. Now, pandas has a built-in DateTime parser and a very good one! Just use pd.to_datetime() on your scalar value or a collection. In this case, however, it won't work, and neither will any external packages that usually help (dateparser is our favorite). And all that because cells describe a time range, and not just one specific date.

Again, let's (at least, for now) see whether we can make our life simpler. Indeed, we probably don't care about specific dates—all we need is the month and year. Luckily, all months are properly stated and uniform—and pd.to_datetime can parse them. So, all we need is to correctly extract two month-year pairs from each.

Now, it seems hard to define one regular expression that will work here. Instead, we can try to get all years (we know all of them are four-digit numbers, starting with 19) and all months (there are just 12 variants). Then, we can combine them, using the year twice if there is only one value.

Let's try it out! First, we define the patterns:

d = ('January', 'February', 'March', 'April', 'May',

'June', "July",' August', 'September', 'October', 'November', 'December')



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.