{"id":147726,"date":"2022-08-15T09:00:00","date_gmt":"2022-08-15T13:00:00","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=147726"},"modified":"2022-11-21T09:57:18","modified_gmt":"2022-11-21T14:57:18","slug":"2-packages-for-extracting-dates-from-a-string-of-text-in-python","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/","title":{"rendered":"2 Packages for Extracting Dates from a String of Text in Python"},"content":{"rendered":"\n<p>This post will cover two different ways to extract dates from strings with Python. The main purpose here is that the strings we will parse contain additional text \u2013 not just the date. Scraping a date out of text can be useful in many different situations.<\/p>\n\n\n\n<p><strong>Option 1) dateutil<\/strong><\/p>\n\n\n\n<p>The first option we\u2019ll show is using the&nbsp;<strong>dateutil<\/strong>&nbsp;package. Here\u2019s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from dateutil.parser import parse\n \nparse(\"Today is 12-01-18\", fuzzy_with_tokens=True)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"517\" height=\"65\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_1-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147736 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_1-the-automatic-net.jpg 517w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_1-the-automatic-net-300x38.jpg 300w\" data-sizes=\"(max-width: 517px) 100vw, 517px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 517px; aspect-ratio: 517\/65;\" \/><\/figure>\n\n\n\n<p>Above, we use a method in&nbsp;<strong>dateutil<\/strong>&nbsp;called&nbsp;<em>parse<\/em>. The first parameter to this method is the string of the text we want to use to search for a date. The second parameter,&nbsp;<em>fuzzy_with_tokens<\/em>, is set equal to True \u2013 this causes the method to return where the date is found in the string. In other words, in the string above, the date is found after the substring \u201cToday is \u201c, which is specified in the tuple output. If we want to get just the returned datetime object, we can do this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>result = parse(\"Today is 12-01-18\", fuzzy_with_tokens=True)\n \n# get just the datetime object\nresult&#91;0]<\/code><\/pre>\n\n\n\n<p>Let\u2019s see how much we can vary a particular date:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>parse(\"Today is December 1, 2018\", fuzzy_with_tokens=True)\n \nparse(\"Today is Dec 1 2018\", fuzzy_with_tokens=True)\n \nparse(\"Today is Dec 1\", fuzzy_with_tokens=True)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"591\" height=\"171\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_2-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147737 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_2-the-automatic-net.jpg 591w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_2-the-automatic-net-300x87.jpg 300w\" data-sizes=\"(max-width: 591px) 100vw, 591px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 591px; aspect-ratio: 591\/171;\" \/><\/figure>\n\n\n\n<p>In the third line of code above, we don\u2019t specify the year. Here,&nbsp;<strong>dateutil<\/strong>&nbsp;assumes by default the year associated with the date is the current one (2018).<\/p>\n\n\n\n<p>If we follow up the last example above of&nbsp;<strong>Dec 1<\/strong>&nbsp;with the two-digit abbreviation of a year,&nbsp;<strong>dateutil<\/strong>&nbsp;is good enough to figure that out:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>parse(\"Today is Dec 1 16\", fuzzy_with_tokens=True)\n \nparse(\"Today is Dec 1 14\", fuzzy_with_tokens=True)\n \nparse(\"Today is Nov 30 12\", fuzzy_with_tokens=True)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"553\" height=\"186\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_3-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147739 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_3-the-automatic-net.jpg 553w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_3-the-automatic-net-300x101.jpg 300w\" data-sizes=\"(max-width: 553px) 100vw, 553px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 553px; aspect-ratio: 553\/186;\" \/><\/figure>\n\n\n\n<p>In the string below, we leave off the year and month, and just say \u201con the 14th.\u201d In this case,&nbsp;<strong>dateutil<\/strong>&nbsp;will assume the month and year are the current month and year, but will parse out the day from the string (in this case, the 14th).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\nparse(\"on the 14th\", fuzzy_with_tokens=True)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"497\" height=\"59\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_4-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147744 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_4-the-automatic-net.jpg 497w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateutils-example_4-the-automatic-net-300x36.jpg 300w\" data-sizes=\"(max-width: 497px) 100vw, 497px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 497px; aspect-ratio: 497\/59;\" \/><\/figure>\n\n\n\n<p>What if we want to pass a string that has multiple dates?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>parse(\"The next one will be on 12-02-18 or 12-03-18\", fuzzy_with_tokens=True)<\/code><\/pre>\n\n\n\n<p>By default, the&nbsp;<strong>parse<\/strong>&nbsp;method will only return the first date found in the string.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-example_4-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147743 lazyload\" width=\"640\" height=\"81\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-example_4-the-automatic-net.jpg 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-example_4-the-automatic-net-300x38.jpg 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/81;\" \/><\/figure>\n\n\n\n<p>We could tinker with the method and write some additional code to handle multiple dates in a string, but there is an alternative in the&nbsp;<strong>dateparser<\/strong>&nbsp;package.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-option-2-extract-dates-from-strings-with-python-dateparser\"><strong>Option 2) Extract dates from strings with Python &amp; dateparser<\/strong><\/h2>\n\n\n\n<p>The&nbsp;<strong>dateparser<\/strong>&nbsp;package comes with an option to search for dates in a string, using a method called&nbsp;<em>search_dates<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from dateparser.search import search_dates\n \nsearch_dates(\"find 12\/15\/18 in this string\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"516\" height=\"59\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_1-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147747 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_1-the-automatic-net.jpg 516w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_1-the-automatic-net-300x34.jpg 300w\" data-sizes=\"(max-width: 516px) 100vw, 516px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 516px; aspect-ratio: 516\/59;\" \/><\/figure>\n\n\n\n<p><strong>search_dates<\/strong>&nbsp;also returns a tuple result, except that the first element of this result is the actual substring identified as a datetime.<\/p>\n\n\n\n<p>Next, if we do the example we did above with&nbsp;<strong>dateutil<\/strong>&nbsp;we get back two results. This is because&nbsp;<strong>dateparser<\/strong>&nbsp;is flagging the word \u201ctoday\u201d as a reference to a date, as well as finding the date \u201c12-01-18.\u201d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>search_dates(\"Today is 12-01-18\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"574\" height=\"105\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_2-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147748 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_2-the-automatic-net.jpg 574w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_2-the-automatic-net-300x55.jpg 300w\" data-sizes=\"(max-width: 574px) 100vw, 574px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 574px; aspect-ratio: 574\/105;\" \/><\/figure>\n\n\n\n<p>Likewise, the examples below also identify the word \u201ctoday\u201d as today\u2019s date, while capturing variations of the date \u201cDecember 1, 2018.\u201d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>search_dates(\"Today is December 1, 2018\")\n \nsearch_dates(\"Today is Dec 1 2018\")\n \nsearch_dates(\"Today is Dec 1\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"599\" height=\"299\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_3-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147750 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_3-the-automatic-net.jpg 599w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_3-the-automatic-net-300x150.jpg 300w\" data-sizes=\"(max-width: 599px) 100vw, 599px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 599px; aspect-ratio: 599\/299;\" \/><\/figure>\n\n\n\n<p>A few more examples like above:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>search_dates(\"Today is Dec 1 16\") \n \nsearch_dates(\"Today is Dec 1 14\")\n \nsearch_dates(\"Today is Nov 30 12\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"593\" height=\"305\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_4-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147932 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_4-the-automatic-net.jpg 593w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-dateparser-search_dates-example_4-the-automatic-net-300x154.jpg 300w\" data-sizes=\"(max-width: 593px) 100vw, 593px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 593px; aspect-ratio: 593\/305;\" \/><\/figure>\n\n\n\n<p>Because&nbsp;<strong>search_dates<\/strong>&nbsp;tells us what substring is matched to a datetime, we could exclude results matching to \u201ctoday\u201d like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>results = search_dates(\"Today is December 1, 2018\")\n \nneed = &#91;result for result in results if result&#91;0].tolower() != \"today\"]<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Here we just use a list comprehension to filter the datetime results to those that don\u2019t match to the word \u201ctoday.\u201d<\/p>\n\n\n\n<p>What if we want to search a longer piece of text? For example, let\u2019s suppose we want to search the&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Python_(programming_language)\">Wikipedia page on Python<\/a>&nbsp;for all the appearing datetimes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># load additional packages\nfrom bs4 import BeautifulSoup\nimport requests\n \n# get HTML content \/ BeautifulSoup object\nresp = requests.get(\"https:\/\/en.wikipedia.org\/wiki\/Python_(programming_language)\")\nsoup = BeautifulSoup(resp.content)\n \n# search for all paragraphs on the webpage \nparagraphs = soup.find_all(\"p\")\n \n# get the text for each paragraph\ntext = &#91;x.text for x in paragraphs]\n \n# scrape any dates from each paragraph\nresults = &#91;]\nfor paragraph in text:\n    try:\n        results.append(search_dates(paragraph))\n    except Exception:\n        pass<\/code><\/pre>\n\n\n\n<p>Now&nbsp;<strong>results<\/strong>&nbsp;contains a list of the datetimes that appear in the Wikipedia page text. We can get a count of how many datetimes were found using the below code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>counts = &#91;0 if result is None else len(result) for result in results]\n \nsum(counts)<\/code><\/pre>\n\n\n\n<p>Above, we use a list comprehension again. This time, we loop through the datetime results, giving a count of zero if&nbsp;<strong>None<\/strong>&nbsp;is returned for a given paragraph (i.e. if no datetime is found in a paragraph); otherwise the number of datetimes gets returned and stored in the list,&nbsp;<strong>counts<\/strong>. Summing the&nbsp;<strong>counts<\/strong>&nbsp;variable tells us the total number of datetimes found by searching through all the paragraphs on the webpage. In this case, there are 71.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"640\" height=\"92\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-list-comprehension-if-conditional-datetime-counts-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-147758 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-list-comprehension-if-conditional-datetime-counts-the-automatic-net.jpg 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/07\/python-list-comprehension-if-conditional-datetime-counts-the-automatic-net-300x43.jpg 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/92;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>In this post we covered how to extract dates from strings with Python. For more on working with dates,&nbsp;<a href=\"https:\/\/theautomatic.net\/2020\/02\/12\/handling-dates-with-pythons-maya-package\">check out this post for standardizing dates with Python<\/a>.<\/p>\n\n\n\n<p>See my other Python posts&nbsp;<a href=\"https:\/\/theautomatic.net\/category\/python\/\">by clicking here<\/a>.<\/p>\n\n\n\n<p><em>Visit <a href=\"https:\/\/theautomatic.net\/2018\/12\/18\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/\">TheAutomatic.net<\/a> to learn more about this topic. <\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will cover two different ways to extract dates from strings with Python.<\/p>\n","protected":false},"author":388,"featured_media":33705,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,349,338,341,352,344],"tags":[806,12278,12277,595],"contributors-categories":[13695],"class_list":{"0":"post-147726","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-python-development","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-quant-north-america","12":"category-quant-regions","13":"tag-data-science","14":"tag-dateparser-package","15":"tag-dateutil-package","16":"tag-python","17":"contributors-categories-theautomatic-net"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>2 Packages for Extracting Dates from a String of Text in Python<\/title>\n<meta name=\"description\" content=\"This post will cover two different ways to extract dates from strings with Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/147726\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"2 Packages for Extracting Dates from a String of Text in Python | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"This post will cover two different ways to extract dates from strings with Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-15T13:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:57:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/01\/python-circuits-hand.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrew Treadway\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Treadway\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Andrew Treadway\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\"\n\t            },\n\t            \"headline\": \"2 Packages for Extracting Dates from a String of Text in Python\",\n\t            \"datePublished\": \"2022-08-15T13:00:00+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:57:18+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/\"\n\t            },\n\t            \"wordCount\": 712,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/01\\\/python-circuits-hand.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"dateparser package\",\n\t                \"dateutil package\",\n\t                \"Python\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"Quant North America\",\n\t                \"Quant Regions\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/\",\n\t            \"name\": \"2 Packages for Extracting Dates from a String of Text in Python | IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/01\\\/python-circuits-hand.jpg\",\n\t            \"datePublished\": \"2022-08-15T13:00:00+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:57:18+00:00\",\n\t            \"description\": \"This post will cover two different ways to extract dates from strings with Python.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/01\\\/python-circuits-hand.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/01\\\/python-circuits-hand.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 540,\n\t            \"caption\": \"Python\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\",\n\t            \"name\": \"Andrew Treadway\",\n\t            \"description\": \"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \\\/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\\\/\\\/www.linkedin.com\\\/in\\\/andrew-treadway-a3b19b103\\\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.\",\n\t            \"sameAs\": [\n\t                \"https:\\\/\\\/theautomatic.net\\\/about-me\\\/\"\n\t            ],\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/andrewtreadway\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"2 Packages for Extracting Dates from a String of Text in Python","description":"This post will cover two different ways to extract dates from strings with Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/147726\/","og_locale":"en_US","og_type":"article","og_title":"2 Packages for Extracting Dates from a String of Text in Python | IBKR Quant Blog","og_description":"This post will cover two different ways to extract dates from strings with Python.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/","og_site_name":"IBKR Campus US","article_published_time":"2022-08-15T13:00:00+00:00","article_modified_time":"2022-11-21T14:57:18+00:00","og_image":[{"width":900,"height":540,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/01\/python-circuits-hand.jpg","type":"image\/jpeg"}],"author":"Andrew Treadway","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andrew Treadway","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/"},"author":{"name":"Andrew Treadway","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc"},"headline":"2 Packages for Extracting Dates from a String of Text in Python","datePublished":"2022-08-15T13:00:00+00:00","dateModified":"2022-11-21T14:57:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/"},"wordCount":712,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/01\/python-circuits-hand.jpg","keywords":["Data Science","dateparser package","dateutil package","Python"],"articleSection":["Data Science","Python Development","Quant","Quant Development","Quant North America","Quant Regions"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/","name":"2 Packages for Extracting Dates from a String of Text in Python | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/01\/python-circuits-hand.jpg","datePublished":"2022-08-15T13:00:00+00:00","dateModified":"2022-11-21T14:57:18+00:00","description":"This post will cover two different ways to extract dates from strings with Python.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/2-packages-for-extracting-dates-from-a-string-of-text-in-python\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/01\/python-circuits-hand.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/01\/python-circuits-hand.jpg","width":900,"height":540,"caption":"Python"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc","name":"Andrew Treadway","description":"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\/\/www.linkedin.com\/in\/andrew-treadway-a3b19b103\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.","sameAs":["https:\/\/theautomatic.net\/about-me\/"],"url":"https:\/\/www.interactivebrokers.com\/campus\/author\/andrewtreadway\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/01\/python-circuits-hand.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/147726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/388"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=147726"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/147726\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/33705"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=147726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=147726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=147726"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=147726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}