<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to count the number of days between events in a flat file (Python, R, or VBA)? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410997#M32402</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you getting that error with the first record or part-way through the records?&amp;nbsp; (You can check by seeing if service_days is empty or not).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a record has a NULL, the cursor returns a NoneType.&amp;nbsp; Are there any gaps in values in the records or is every row of every column populated?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Jan 2018 13:57:36 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2018-01-26T13:57:36Z</dc:date>
    <item>
      <title>How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410983#M32388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all!&lt;/P&gt;&lt;P&gt;So I am working on a project and I've hit a roadblock.&lt;/P&gt;&lt;P&gt;What I want to do is find the number of days that a parcel (identified by 'PREM_CODE') had water service during a two year period.&lt;/P&gt;&lt;P&gt;However, the structure of the data is giving me some issues. Each row in this table represents a water meter reading and whether the water was turned on or off. If the water was turned on, the value in the field 'ACTN_CODE' would be 'IN,' if the meter was being turned off, the value would be 'OUT.'&lt;/P&gt;&lt;P&gt;There are a few assumptions that I need to put into a logic to deal with these that are giving me trouble. Those assumptions are:&lt;/P&gt;&lt;P&gt;If a premises's (PREM_CODE) first chronological event is a turn-on event (i.e. 'ACTN_CODE'='IN'), then use that date should be used as the starting date (Below Example 89 and 99).&lt;/P&gt;&lt;P&gt;If a premises's (PREM_CODE) first chronological event is a turn-off event (i.e. 'ACTN_CODE'='OUT'), then subtract the number of days between the period's first date (7/1/2015) to the date of the event (ACTION_DATE) (Below Example 50,76, and 152).&lt;/P&gt;&lt;P&gt;Then, after that first logic is implemented, I need to count the days between any subsequent 'IN' and 'OUT' events.&lt;/P&gt;&lt;P&gt;If a PREM_CODE's last entry is an 'IN' event, then I need to subtract that 'IN' event's date from the end date, which is 8/1/2017.&lt;/P&gt;&lt;P&gt;And lastly, if a PREM_CODE's last entry is an 'OUT,' then no further calculations should be made.&lt;/P&gt;&lt;P&gt;Here is a sample of what this could look like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;**Start date = 7/1/2015&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;**End date = 8/1/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE class="j-table jiveBorder" style="border: 1px solid #c6c6c6;" width="100%"&gt;&lt;THEAD&gt;&lt;TR style="background-color: #efefef;"&gt;&lt;TH&gt;PREM_CODE&lt;/TH&gt;&lt;TH&gt;ACTN_CODE&lt;/TH&gt;&lt;TH&gt;ACTION_DATE&lt;/TH&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;OUT&lt;/TD&gt;&lt;TD&gt;7/30/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;IN&lt;/TD&gt;&lt;TD&gt;9/21/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;89&lt;/TD&gt;&lt;TD&gt;IN&lt;/TD&gt;&lt;TD&gt;10/10/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;OUT&lt;/TD&gt;&lt;TD&gt;12/1/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;IN&lt;/TD&gt;&lt;TD&gt;1/1/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;OUT&lt;/TD&gt;&lt;TD&gt;9/1/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;IN&lt;/TD&gt;&lt;TD&gt;5/5/2017&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;99&lt;/TD&gt;&lt;TD&gt;IN&lt;/TD&gt;&lt;TD&gt;7/30/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;152&lt;/TD&gt;&lt;TD&gt;OUT&lt;/TD&gt;&lt;TD&gt;7/1/2017&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each of these has its own unique situation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For PREM_CODE=50, the calulcation would be: (7/1/2015-7/30/2016)+(9/21/2016-8/1/2017)&lt;BR /&gt;For PREM_CODE=89, the calculation would be: (10/10/2015-8/1/2017)&lt;BR /&gt;For PREM_CODE=76, the calculation would be:(7/1/2015-12/1/2015)+(1/1/2016-9/1/2016)+(5/5/2017-8/1/2017)&lt;BR /&gt;For PREM_CODE=99, the calculation would be: (7/30/2015-8/1/2017)&lt;BR /&gt;For PREM_CODE=152, the calculation would be: (7/1/2015-7/1/2017)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any and all help would be appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 14:09:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410983#M32388</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-25T14:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410984#M32389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following still feels a bit clunky to me, but it should get the job done.&amp;nbsp; The result is a dictionary of service days by premises code.&amp;nbsp; Since you have dates, and not dates and times, I wasn't sure how you wanted to handle partial service days.&amp;nbsp; I assumed a partial service day counted as a full service day, e.g., getting hooked up on 07/01 and disconnected on 07/02 would be 2 days of service.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; datetime
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; itertools


tbl &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to table containing service events&lt;/SPAN&gt;
fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PREM_CODE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"ACTION_DATE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"ACTN_CODE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
start_period &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2015&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;7&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
end_period &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2017&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;8&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

service_days &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; dict&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tbl&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sorted_events &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sorted&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;cur&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; key&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;lambda&lt;/SPAN&gt; x&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; x&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; k&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; g &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; itertools&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;groupby&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sorted_events&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; key&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;lambda&lt;/SPAN&gt; x&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; x&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prem&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; action &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;g&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; action &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"OUT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; service_days&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;prem&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; start_period&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;days &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; action &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"IN"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; service_days&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;prem&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; prem&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; action &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; g&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; action &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"OUT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; service_days&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;prem&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; in_date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;days &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; action &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"IN"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; action &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"IN"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; service_days&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;prem&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;end_period &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;days &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If your tables are huge, you could have the cursor do the sorting first instead of dumping the cursor into a list using &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;sorted&lt;/SPAN&gt;, but most GIS users aren't really working with huge data sets.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:39:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410984#M32389</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T18:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410985#M32390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome! I'll give this a try!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the dataset&amp;nbsp;is pretty big (300k rows)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll let you know how it goes!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:09:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410985#M32390</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-25T16:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410986#M32391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By modern computing standards, 300k isn't that large.&amp;nbsp; My 3+ year-old laptop can probably process a table with 1 million records in a few seconds, maybe 10 seconds.&amp;nbsp; And with machines having GBs and GBs of RAM, loading 300k records into memory usually is no problem unless the records have lots of large BLOB or verbose text fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:14:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410986#M32391</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-01-25T16:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410987#M32392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fantastic, and do you foresee any difference in behavior between CSV, xlsx, xls, etc?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:16:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410987#M32392</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-25T16:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410988#M32393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My code is based on the assumption that ArcGIS is treating ACTION_DATE as a date field.&amp;nbsp; Since CSV, XLS, and XLSX can be a bit loose with data types, I would just confirm the ACTION_DATE field is being treated as date.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:21:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410988#M32393</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-01-25T16:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410989#M32394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm getting a curious error that seems dependent on file type. Csv's get read but fail with a 'invalid column name error,' but xls and xlsx fail with a 'could not open C:\...'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:32:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410989#M32394</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-25T16:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410990#M32395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it's worth anything, I've attached the .csv here as a downloadable item in AGOL:&amp;nbsp;&lt;A class="link-titled" href="http://www.arcgis.com/home/item.html?id=67c5dd7000094f7ab0049e7d38764a24" title="http://www.arcgis.com/home/item.html?id=67c5dd7000094f7ab0049e7d38764a24"&gt;http://www.arcgis.com/home/item.html?id=67c5dd7000094f7ab0049e7d38764a24&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:39:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410990#M32395</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-25T16:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410991#M32396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would just swim downstream and copy the contents into a table in a file geodatabase.&amp;nbsp; Then you can verify the field data types are going to be set correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:44:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410991#M32396</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-01-25T16:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410992#M32397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's the trick!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And does the output come as a total? Or is it broken out by PREM_CODE? I'm looking for the latter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 19:04:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410992#M32397</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-25T19:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410993#M32398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;sum&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;service_days&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;values&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 19:18:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410993#M32398</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-01-25T19:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410994#M32399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmmm, that doesn't seem to do it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've attached a video of what I'm seeing...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I feel like i'm missing something.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've added a few print statements as smoketests as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6162396568001w320h240r738" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6162396568001" data-account="6161463677001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6161463677001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6162396568001w320h240r738');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.esri.com/t5/video/gallerypage/video-id/6162396568001"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 19:30:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410994#M32399</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-25T19:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410995#M32400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You altered some of my code, make sure the following:&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;fields &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;"PREM_CODE"&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;"ACTION_DATE"&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;"ACTN_CODE"&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 23:25:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410995#M32400</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-01-25T23:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410996#M32401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Made that change and now I'm getting an error of 'can't compare datetime.datetime to NoneType'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps the issue is coming from the datetime in .gdbs is always stored as MM:DD:YYYY hh:mm:ss, regardless of how the data is actually displayed in the table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you think the mistmatch between the 'start_period' and 'end_period' and the gdb's date storage would cause an issue here? Or do you think it would be something else?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2018 13:46:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410996#M32401</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-26T13:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410997#M32402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you getting that error with the first record or part-way through the records?&amp;nbsp; (You can check by seeing if service_days is empty or not).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a record has a NULL, the cursor returns a NoneType.&amp;nbsp; Are there any gaps in values in the records or is every row of every column populated?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2018 13:57:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410997#M32402</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-01-26T13:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of days between events in a flat file (Python, R, or VBA)?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410998#M32403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And there it is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A single null date field &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/grin.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I owe you a beer at either the User Conference or Dev summit!&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2018 14:02:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-count-the-number-of-days-between-events-in/m-p/410998#M32403</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-01-26T14:02:35Z</dc:date>
    </item>
  </channel>
</rss>

