<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Austin</title>
    <description>The latest articles on Forem by Austin (@austin_62).</description>
    <link>https://forem.com/austin_62</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1049710%2F9d3775b9-8609-4776-a9c9-e393acfe1855.jpeg</url>
      <title>Forem: Austin</title>
      <link>https://forem.com/austin_62</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/austin_62"/>
    <language>en</language>
    <item>
      <title>NYC Collision Data Analysis</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Mon, 28 Aug 2023 02:29:26 +0000</pubDate>
      <link>https://forem.com/austin_62/nyc-collision-data-analysis-48pp</link>
      <guid>https://forem.com/austin_62/nyc-collision-data-analysis-48pp</guid>
      <description>&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://aibistin.github.io/crash_stats/crash_time_period_stats.html" rel="noopener noreferrer"&gt;
      aibistin.github.io
    &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>pandas</category>
      <category>data</category>
    </item>
    <item>
      <title>Crash City</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Fri, 07 Apr 2023 17:00:27 +0000</pubDate>
      <link>https://forem.com/austin_62/crash-city-2ebd</link>
      <guid>https://forem.com/austin_62/crash-city-2ebd</guid>
      <description>&lt;h2&gt;
  
  
  Analyzing NYC Traffic Collision Data on the Linux Command Line with SoQL and Curl
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.aibistin.com/?p=1020"&gt;Original Post&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;New York City and the NYPD publish a dataset of traffic collisions, related fatalities, injuries and other details &lt;a href="https://dev.socrata.com/foundry/data.cityofnewyork.us/h9gi-nx95"&gt;here&lt;/a&gt;.&lt;br&gt;
This was first published in July 2012, and is updated regularly to this date. &lt;/p&gt;

&lt;p&gt;NYC Commuters, especially pedestrians and cyclists, have to endure many hazards just to get to and from work. Crime is one issue, but it's not as treacherous as crossing Queens Boulevard during rush hour, or cycling in downtown Manhattan when &lt;a href="https://www.nova.ie/wp-content/uploads/2020/05/Clown-Car.jpg"&gt;some clown&lt;/a&gt; driving an SUV the size of an &lt;a href="https://www.motorbiscuit.com/american-trucks-suvs-almost-bigger-world-war-ii-tanks/"&gt;Sherman tank&lt;/a&gt; is taking up half the road. &lt;/p&gt;

&lt;p&gt;Previously I did some &lt;a href="https://www.aibistin.com/?p=907"&gt;analysis&lt;/a&gt; using their downloadable CSV dataset.&lt;br&gt;&lt;br&gt;
Here I’m going to use the &lt;a href="https://www.man7.org/linux/man-pages/man1/curl.1.html"&gt;curl&lt;/a&gt; utility along with the &lt;a href="https://docs.oracle.com/en/database/oracle/simple-oracle-document-access/rest/index.html"&gt;SODA&lt;/a&gt; or &lt;a href="https://dev.socrata.com/docs/endpoints.html"&gt;SoQL Query Language&lt;/a&gt;, to try and make some sense out of this published &lt;a href="https://dev.socrata.com/foundry/data.cityofnewyork.us/h9gi-nx95"&gt;data&lt;/a&gt;. &lt;/p&gt;
&lt;h3&gt;
  
  
  Using the Socrata Query Language, SoQL
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.socrata.com/docs/app-tokens.html"&gt;Dataset App Token&lt;/a&gt;&lt;br&gt;
Socrata &lt;a href="https://dev.socrata.com/docs/functions/#,"&gt;functions&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How many collisions since July 2012
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--get&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$\$&lt;/span&gt;&lt;span class="s2"&gt;app_token=uvwxyz"&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=count(*)"&lt;/span&gt; https://data.cityofnewyork.us/resource/h9gi-nx95.json 
&lt;span class="o"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"count"&lt;/span&gt;:&lt;span class="s2"&gt;"1977803"&lt;/span&gt;&lt;span class="o"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;curl --get&lt;/code&gt; or &lt;code&gt;-G&lt;/code&gt;&lt;br&gt;
Use the GET verb as we are ‘getting’ data&lt;br&gt;
&lt;code&gt;v&lt;/code&gt; &lt;br&gt;
Lots of verbose output as you can see from the above output.&lt;br&gt;
&lt;code&gt;d&lt;/code&gt; &lt;br&gt;
Request data to pass to the API in ASCII format&lt;br&gt;
&lt;code&gt;--data-urlencode&lt;/code&gt;&lt;br&gt;
URL-Encode the data. Safer than just using &lt;code&gt;-d&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$$app_token&lt;/code&gt;&lt;br&gt;
Users personal authorization. Not really necessary for ad-hoc requests&lt;br&gt;
Socrata open data API [App-Token]](&lt;a href="https://dev.socrata.com/docs/app-tokens.html"&gt;https://dev.socrata.com/docs/app-tokens.html&lt;/a&gt;)&lt;br&gt;
I replaced my actual token with ‘uvwxyz’ for fairly obvious reasons&lt;br&gt;
&lt;code&gt;"$select=count(*)"&lt;/code&gt;&lt;br&gt;
Similar to the SQL &lt;code&gt;SELECT&lt;/code&gt; and SQL &lt;code&gt;count&lt;/code&gt; aggregate function&lt;br&gt;
SoQL &lt;a href="https://dev.socrata.com/docs/queries/select.html"&gt;$select&lt;/a&gt;&lt;br&gt;
SoQL  &lt;a href="https://dev.socrata.com/docs/functions/count.html"&gt;count&lt;/a&gt; &lt;/p&gt;
&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;

&lt;p&gt;1,977,803 Collisions from July 2012 to March 2023 seems like a lot to me. You’d wonder what’s the point of driving tests if we still end up with this many collisions. &lt;/p&gt;
&lt;h3&gt;
  
  
  Getting all the collision records between two arbitrary dates, June 30th 2022 to December 31 2022.
&lt;/h3&gt;

&lt;p&gt;This time I’ll use the &lt;code&gt;-v&lt;/code&gt; switch for curl to get a much more verbose output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; curl &lt;span class="nt"&gt;--get&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt;  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$\$&lt;/span&gt;&lt;span class="s2"&gt;app_token=xyz"&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=*"&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;where=crash_date between '2022-06-30T00:00:00.000' and '2022-12-31T00:00:00.000'"&lt;/span&gt;  https://data.cityofnewyork.us/resource/h9gi-nx95.json

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 &lt;span class="nt"&gt;--&lt;/span&gt;:--:-- &lt;span class="nt"&gt;--&lt;/span&gt;:--:-- &lt;span class="nt"&gt;--&lt;/span&gt;:--:--     0&lt;span class="k"&gt;*&lt;/span&gt;   Trying 52.206.68.26:443...
&lt;span class="k"&gt;*&lt;/span&gt; Connected to data.cityofnewyork.us &lt;span class="o"&gt;(&lt;/span&gt;52.206.68.26&lt;span class="o"&gt;)&lt;/span&gt; port 443 &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="c"&gt;#0)&lt;/span&gt;
...
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; GET /resource/h9gi-nx95.json?&lt;span class="nv"&gt;$$app_token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;xyz&amp;amp;&lt;span class="nv"&gt;$select&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;%2A&amp;amp;&lt;span class="nv"&gt;$where&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;crash_date+between+%272022-06-30T00%3A00%3A00.000%27+and+%272022-12-31T00%3A00%3A00.000%27 HTTP/1.1
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Host: data.cityofnewyork.us
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; User-Agent: curl/7.81.0
...
&amp;lt; HTTP/1.1 200 OK
....
&amp;lt; X-SODA2-Fields: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"crash_date"&lt;/span&gt;,&lt;span class="s2"&gt;"crash_time"&lt;/span&gt;,&lt;span class="s2"&gt;"borough"&lt;/span&gt;,&lt;span class="s2"&gt;"zip_code"&lt;/span&gt;,&lt;span class="s2"&gt;"latitude"&lt;/span&gt;,&lt;span class="s2"&gt;"longitude"&lt;/span&gt;,&lt;span class="s2"&gt;"location"&lt;/span&gt;,&lt;span class="s2"&gt;"on_street_name"&lt;/span&gt;,&lt;span class="s2"&gt;"off_street_name"&lt;/span&gt;,&lt;span class="s2"&gt;"cross_street_name"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_persons_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_persons_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_1"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_2"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_3"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_4"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_5"&lt;/span&gt;,&lt;span class="s2"&gt;"collision_id"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code1"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code2"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code_3"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code_4"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code_5"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&amp;lt; X-SODA2-Types: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"floating_timestamp"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"location"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&amp;lt; X-SODA2-Data-Out-Of-Date: &lt;span class="nb"&gt;false&lt;/span&gt;
...
&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;14733 bytes data]
...
&lt;span class="o"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"crash_date"&lt;/span&gt;:&lt;span class="s2"&gt;"2022-06-30T00:00:00.000"&lt;/span&gt;,&lt;span class="s2"&gt;"crash_time"&lt;/span&gt;:&lt;span class="s2"&gt;"14:01"&lt;/span&gt;,&lt;span class="s2"&gt;"cross_street_name"&lt;/span&gt;:&lt;span class="s2"&gt;"101       EAST DRIVE"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_persons_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"1"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_p
ersons_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"1"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_killed"&lt;/span&gt;:
&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_1"&lt;/span&gt;:&lt;span class="s2"&gt;"Pedestrian/Bicyclist/Other Pedestrian Error/Con
fusion"&lt;/span&gt;,&lt;span class="s2"&gt;"collision_id"&lt;/span&gt;:&lt;span class="s2"&gt;"4542318"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code1"&lt;/span&gt;:&lt;span class="s2"&gt;"Bike"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
...
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"crash_date"&lt;/span&gt;:&lt;span class="s2"&gt;"2022-07-03T00:00:00.000"&lt;/span&gt;,&lt;span class="s2"&gt;"crash_time"&lt;/span&gt;:&lt;span class="s2"&gt;"22:30"&lt;/span&gt;,&lt;span class="s2"&gt;"borough"&lt;/span&gt;:&lt;span class="s2"&gt;"BRONX"&lt;/span&gt;,&lt;span class="s2"&gt;"zip_code"&lt;/span&gt;:&lt;span class="s2"&gt;"10458"&lt;/span&gt;,&lt;span class="s2"&gt;"latitude"&lt;/span&gt;:&lt;span class="s2"&gt;"40.866802"&lt;/span&gt;,&lt;span class="s2"&gt;"longitude"&lt;/span&gt;:&lt;span class="s2"&gt;"-73.88444"&lt;/span&gt;,&lt;span class="s2"&gt;"location"&lt;/span&gt;:&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"latitude"&lt;/span&gt;:&lt;span class="s2"&gt;"40.866802"&lt;/span&gt;,&lt;span class="s2"&gt;"longitude"&lt;/span&gt;:&lt;span class="s2"&gt;"-73.88444"&lt;/span&gt;,&lt;span class="s2"&gt;"human_address"&lt;/span&gt;:&lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;address&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"\"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;city&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"\"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;state&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"\"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;zip&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"\"&lt;/span&gt;&lt;span class="s2"&gt;}"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;,&lt;span class="s2"&gt;"on_street_name"&lt;/span&gt;:&lt;span class="s2"&gt;"WEBSTER AVENUE"&lt;/span&gt;,&lt;span class="s2"&gt;"off_street_name"&lt;/span&gt;:&lt;span class="s2"&gt;"EAST 199 STREET"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_persons_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_persons_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"0"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_1"&lt;/span&gt;:&lt;span class="s2"&gt;"Driver Inattention/Distraction"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_2"&lt;/span&gt;:&lt;span class="s2"&gt;"Unspecified"&lt;/span&gt;,&lt;span class="s2"&gt;"collision_id"&lt;/span&gt;:&lt;span class="s2"&gt;"4543075"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code1"&lt;/span&gt;:&lt;span class="s2"&gt;"Station Wagon/Sport Utility Vehicle"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code2"&lt;/span&gt;:&lt;span class="s2"&gt;"Station Wagon/Sport Utility Vehicle"&lt;/span&gt;&lt;span class="o"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;1000 records&lt;br&gt;
When no &lt;code&gt;$limit&lt;/code&gt; is set, this is the default maximum rows returned&lt;br&gt;
&lt;code&gt;curl --get&lt;/code&gt; or &lt;code&gt;-G&lt;/code&gt;&lt;br&gt;
Use the GET verb as we are ‘getting’ data&lt;br&gt;
&lt;code&gt;-v&lt;/code&gt; &lt;br&gt;
Lots of verbose output as you can see &lt;br&gt;
&lt;code&gt;-d&lt;/code&gt; &lt;br&gt;
Request data to pass to the API in ASCII format&lt;br&gt;
&lt;code&gt;--data-urlencode&lt;/code&gt;&lt;br&gt;
URL-Encode the data. Safer than just using &lt;code&gt;-d&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$$app_token&lt;/code&gt;&lt;br&gt;
Users personal authorization. Not really necessary for ad-hoc requests&lt;br&gt;
&lt;code&gt;"$select=*"&lt;/code&gt;&lt;br&gt;
Similar to an SQL &lt;code&gt;SELECT&lt;/code&gt;&lt;br&gt;
Selecting all columns. This is the default and can be omitted&lt;br&gt;
SoQL &lt;a href="https://dev.socrata.com/docs/queries/select.html"&gt;$select&lt;/a&gt;&lt;br&gt;
&lt;code&gt;$where&lt;/code&gt;&lt;br&gt;
Similar to SQL &lt;code&gt;WHERE&lt;/code&gt; to filter down data. &lt;br&gt;
SoQL &lt;a href="https://dev.socrata.com/docs/queries/where.html"&gt;$where&lt;/a&gt;&lt;br&gt;
&lt;code&gt;between … and …&lt;/code&gt;&lt;br&gt;
SoQL &lt;a href="https://dev.socrata.com/docs/functions/between.html"&gt;between&lt;/a&gt;&lt;br&gt;
Narrow our results down to collisions between the two *&lt;em&gt;inclusive&lt;/em&gt; ‘crash_date’ values&lt;/p&gt;
&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;

&lt;p&gt;It turns out after piping this request to a &lt;code&gt;wc&lt;/code&gt; command, that the API only returns 1000 rows, which is the default maximum amount if the &lt;code&gt;$limit&lt;/code&gt; clause isn’t specified. With the &lt;code&gt;$limit&lt;/code&gt; clause, the maximum amount that can be returned with one call is 50,000 rows. To get more, you will need to order and &lt;a href="https://dev.socrata.com/docs/paging.html"&gt;page&lt;/a&gt; through the data. &lt;br&gt;
One other thing to note here is that when using the &lt;code&gt;-v&lt;/code&gt;, verbose switch, you get to see the column names and their data types. &lt;/p&gt;
&lt;h5&gt;
  
  
  The NYC dataset column names
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="s2"&gt;"crash_date"&lt;/span&gt;,&lt;span class="s2"&gt;"crash_time"&lt;/span&gt;,&lt;span class="s2"&gt;"borough"&lt;/span&gt;,&lt;span class="s2"&gt;"zip_code"&lt;/span&gt;,&lt;span class="s2"&gt;"latitude"&lt;/span&gt;,&lt;span class="s2"&gt;"longitude"&lt;/span&gt;,&lt;span class="s2"&gt;"location"&lt;/span&gt;,&lt;span class="s2"&gt;"on_street_name"&lt;/span&gt;,&lt;span class="s2"&gt;"off_street_name"&lt;/span&gt;,&lt;span class="s2"&gt;"cross_street_name"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_persons_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_persons_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_pedestrians_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_cyclist_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_injured"&lt;/span&gt;,&lt;span class="s2"&gt;"number_of_motorist_killed"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_1"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_2"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_3"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_4"&lt;/span&gt;,&lt;span class="s2"&gt;"contributing_factor_vehicle_5"&lt;/span&gt;,&lt;span class="s2"&gt;"collision_id"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code1"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code2"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code_3"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code_4"&lt;/span&gt;,&lt;span class="s2"&gt;"vehicle_type_code_5"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Corresponding Field Data Types
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="s2"&gt;"floating_timestamp"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"location"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"number"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;,&lt;span class="s2"&gt;"text"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  SoQL &lt;a href="https://dev.socrata.com/docs/queries/"&gt;Query Clauses&lt;/a&gt; from the Docs
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Default&lt;/th&gt;
&lt;th&gt;In $query&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;$select&lt;/td&gt;
&lt;td&gt;The set of columns to be returned, similar to a SELECT in SQL&lt;/td&gt;
&lt;td&gt;All columns, equivalent to $select=*&lt;/td&gt;
&lt;td&gt;SELECT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$where&lt;/td&gt;
&lt;td&gt;Filters the rows to be returned, similar to WHERE&lt;/td&gt;
&lt;td&gt;No filter&lt;/td&gt;
&lt;td&gt;WHERE&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$order&lt;/td&gt;
&lt;td&gt;Column to order results on, similar to ORDER BY in SQL&lt;/td&gt;
&lt;td&gt;Unspecified order&lt;/td&gt;
&lt;td&gt;ORDER BY&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$group&lt;/td&gt;
&lt;td&gt;Column to group results on, similar to GROUP BY in SQL&lt;/td&gt;
&lt;td&gt;No grouping&lt;/td&gt;
&lt;td&gt;GROUP BY&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$having&lt;/td&gt;
&lt;td&gt;Filters the rows that result from an aggregation, similar to HAVING&lt;/td&gt;
&lt;td&gt;No filter&lt;/td&gt;
&lt;td&gt;HAVING&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$limit&lt;/td&gt;
&lt;td&gt;Maximum number of results to return&lt;/td&gt;
&lt;td&gt;1000 (2.0 endpoints: maximum of 50,000; 2.1: unlimited »)&lt;/td&gt;
&lt;td&gt;LIMIT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$offset&lt;/td&gt;
&lt;td&gt;Offset count into the results to start at, used for paging&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;OFFSET&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$q&lt;/td&gt;
&lt;td&gt;Performs a full text search for a value.&lt;/td&gt;
&lt;td&gt;No search&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$query&lt;/td&gt;
&lt;td&gt;A full SoQL query string, all as one parameter&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$$bom&lt;/td&gt;
&lt;td&gt;Prepends a UTF-8 Byte Order Mark to the beginning of CSV output&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Get all the collisions for zip code 10036, Times Square NYC, for Feb 2023
&lt;/h3&gt;

&lt;p&gt;Save it into file &lt;code&gt;times_square_july_2022.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--get&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$\$&lt;/span&gt;&lt;span class="s2"&gt;app_token=uvwxyz"&lt;/span&gt;  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=*"&lt;/span&gt; / &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;where=crash_date between '2023-02-01T00:00:00.000' and '2023-02-28T00:00:00.000'"&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"zip_code=10036"&lt;/span&gt;  https://data.cityofnewyork.us/resource/h9gi-nx95.json &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;    collisions_z10036_feb_2023.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;"\$where=crash_date between '2023-02-01T00:00:00.000' and '2023-02-28T00:00:00.000'" --data-urlencode "zip_code=10036"&lt;br&gt;&lt;br&gt;
Specify dates between and including February 1st to the 28th.&lt;br&gt;
 &lt;code&gt;zip_code=10036&lt;/code&gt;  to narrow down our results. &lt;/p&gt;

&lt;p&gt;Count how many collisions using the Linux &lt;code&gt;wc&lt;/code&gt; command with our newly created file, &lt;code&gt;times_square_july_2022.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; collisions_z10036_feb_2023.json 
25 collisions_z10036_feb_2023.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Double check that count of 25 collisions, using the SoQl &lt;code&gt;count(*)&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; curl &lt;span class="nt"&gt;--get&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$\$&lt;/span&gt;&lt;span class="s2"&gt;app_token=uvwxyz"&lt;/span&gt;  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=count(*)"&lt;/span&gt;  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;where=crash_date between '2023-02-01T00:00:00.000' and '2023-02-28T00:00:00.000'"&lt;/span&gt; &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"zip_code=10036"&lt;/span&gt;  https://data.cityofnewyork.us/resource/h9gi-nx95.json 
&lt;span class="o"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"count"&lt;/span&gt;:&lt;span class="s2"&gt;"25"&lt;/span&gt;&lt;span class="o"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;\$select=count(*)&lt;/code&gt;&lt;br&gt;
Similar to the SQL &lt;code&gt;count&lt;/code&gt; function, this uses the SoQL &lt;a href="https://dev.socrata.com/docs/functions/count.html"&gt;count&lt;/a&gt; function to count the number of rows that match our search criteria. &lt;br&gt;
&lt;code&gt;[{"count":"25"}]&lt;/code&gt;,  which matches the number of records in the collisions_z10036_feb_2023.json file&lt;/p&gt;
&lt;h3&gt;
  
  
  Observation
&lt;/h3&gt;

&lt;p&gt;25 collisions in one midtown zip code for February is almost 1 collision a day. I’m sure that's lower than many other zip codes. &lt;/p&gt;
&lt;h3&gt;
  
  
  Get the 10 worst zip codes for collisions in February 2023
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; curl &lt;span class="nt"&gt;--get&lt;/span&gt; &lt;span class="nt"&gt;--silent&lt;/span&gt;  ‘&lt;span class="nv"&gt;$$app_token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;uvwxyz’  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=count(*), zip_code"&lt;/span&gt;   &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;where=crash_date between '2023-02-01T00:00:00.000' and '2023-02-28T00:00:00.000'"&lt;/span&gt;  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$group=zip_code'&lt;/span&gt;   https://data.cityofnewyork.us/resource/h9gi-nx95.json | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.[] | .zip_code + " " + .count'&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt;  &lt;span class="nt"&gt;-k&lt;/span&gt; 2,2nr &lt;span class="nt"&gt;-k&lt;/span&gt; 1n | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n10&lt;/span&gt;
11207 105
11212 85
11208 79
11226 75
11234 72
11236 72
11101 71
11203 67
11368 67
11211 62
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;OK, I threw in a lot of commands here. &lt;br&gt;
"\$select=count(*), zip_code" &lt;br&gt;
Selecting the count and zip_code&lt;br&gt;
 SoQL &lt;a href="https://dev.socrata.com/docs/functions/count.html"&gt;count&lt;/a&gt; function to count the number of rows that match our search criteria. &lt;br&gt;
 &lt;code&gt;$group=zip_code&lt;/code&gt; &lt;br&gt;
Similar to the SQL &lt;code&gt;GROUP BY&lt;/code&gt;&lt;br&gt;
Returns aggregate rows grouped by the &lt;code&gt;zip_code&lt;/code&gt;&lt;br&gt;
 &lt;code&gt;jq -r '.[] | .zip_code + " " + .count'&lt;/code&gt;&lt;br&gt;
Using the very useful  &lt;a href="https://stedolan.github.io/jq/"&gt;jq&lt;/a&gt; to do additional filtering&lt;br&gt;
&lt;code&gt;jq&lt;/code&gt; bills itself as, “a lightweight and flexible command-line JSON processor”&lt;br&gt;
I  extract the zip_code and collision count for each zip code and concatenate them using the &lt;code&gt;bash&lt;/code&gt; +, concatenation operator&lt;br&gt;
&lt;code&gt;sort  -k 2,2nr -k 1n&lt;/code&gt;&lt;br&gt;
Using the bash &lt;a href="https://ss64.com/bash/sort.html"&gt;sort&lt;/a&gt; command, we do a reverse numerical sort by the second field, which is the count. We also do a numerical sort on the zip_code for zip_codes with identical collision counts&lt;br&gt;
&lt;code&gt;head -n10&lt;/code&gt;&lt;br&gt;
This gets the first 10, which are the 10 zip codes with the most collisions, starting with the very worst. &lt;/p&gt;
&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;

&lt;p&gt;I could have used SoQL &lt;code&gt;$sort&lt;/code&gt; and &lt;code&gt;$limit&lt;/code&gt; to do some of this work, but I chose the &lt;code&gt;bash&lt;/code&gt; sort, just because ... &lt;br&gt;
Zip code &lt;a href="https://www.unitedstateszipcodes.org/11207"&gt;11207&lt;/a&gt;, East New York, Brooklyn, emerges as the zip with the most collisions in February. &lt;br&gt;
This zip has a lot of issues with traffic safety, as you could also check &lt;a href="https://www.aibistin.com/?p=907"&gt;here&lt;/a&gt; . &lt;br&gt;
105 collisions in one month.  3.75 a day? There’s something seriously wrong there. You’d probably need some kind of armor suit just to cross the street there. &lt;/p&gt;
&lt;h3&gt;
  
  
  As the queries get more complex, these one line commands start to get long and hard to manage.
&lt;/h3&gt;

&lt;p&gt;Curl has an option to create a config file. On a Linux system the default config is usually &lt;code&gt;~/.curlrc&lt;/code&gt;. You can specify a config file with the &lt;code&gt;-K&lt;/code&gt; or &lt;code&gt;--config&lt;/code&gt; switch. &lt;/p&gt;

&lt;p&gt;I created the below config file for these requests&lt;br&gt;
The config file sets the NYC API URL, the $$app_token parameter, a GET request, as well as asking for verbose output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##### The ./.nyc_curlrc file contents
# --- NYC Collision Data ---
get
url = "https://data.cityofnewyork.us/resource/h9gi-nx95.json"
data-urlencode  =  "\$\$app_token=uvwxyz"
verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The previous example can now be rewritten to use the &lt;code&gt;.nyc_curlrc&lt;/code&gt;  config file. I also broke up the commands into separate lines using the bash continuation ‘\’ . Enclosing some of the commands in single quotes also means that the ‘$’ doesn’t need to be escaped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; curl &lt;span class="nt"&gt;-K&lt;/span&gt; ./.nyc_curlrc &lt;span class="se"&gt;\&lt;/span&gt;
 &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$select=count(*), zip_code'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
 &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$where=crash_date between "2023-02-01T00:00:00.000" and "2023-02-28T00:00:00.000"'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
 &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$group=zip_code'&lt;/span&gt;  &lt;span class="se"&gt;\&lt;/span&gt;
  | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.[] | .zip_code + " " + .count'&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt;  &lt;span class="nt"&gt;-k&lt;/span&gt; 2,2nr &lt;span class="nt"&gt;-k&lt;/span&gt; 1n | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a little more concise than the previous version, and yields the same result. &lt;/p&gt;

&lt;p&gt;### Now to find how many cyclists and pedestrians were killed over the duration of this dataset&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; curl &lt;span class="nt"&gt;-K&lt;/span&gt; ./.nyc_curlrc &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=date_extract_y(crash_date) AS year, SUM(number_of_pedestrians_killed) AS tot_pedestrians_killed, SUM(number_of_cyclist_killed) AS tot_cyclist_killed"&lt;/span&gt;  &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;group=year"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;order=tot_pedestrians_killed DESC"&lt;/span&gt;  | jq &lt;span class="nb"&gt;.&lt;/span&gt;

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   885    0   885    0     0   1616      0 &lt;span class="nt"&gt;--&lt;/span&gt;:--:-- &lt;span class="nt"&gt;--&lt;/span&gt;:--:-- &lt;span class="nt"&gt;--&lt;/span&gt;:--:--  1614
&lt;span class="o"&gt;[&lt;/span&gt;
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2013"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"176"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"11"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2016"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"149"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"18"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2014"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"133"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"20"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2015"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"133"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"15"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2022"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"132"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"18"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2019"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"131"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"31"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2021"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"129"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"19"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2017"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"127"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"27"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2018"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"123"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"10"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2020"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"101"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"29"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2012"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"72"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"6"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"year"&lt;/span&gt;: &lt;span class="s2"&gt;"2023"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"18"&lt;/span&gt;,
    &lt;span class="s2"&gt;"tot_cyclist_killed"&lt;/span&gt;: &lt;span class="s2"&gt;"8"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;date_extract_y(crash_date) AS year&lt;br&gt;
Will extract ‘2023’ from ‘2023-02-03T00:00:00.000’&lt;br&gt;
SoQL &lt;a href="https://dev.socrata.com/docs/functions/date_extract_y.html"&gt;date_extract_y&lt;/a&gt;&lt;br&gt;
SUM(number_of_pedestrians_killed) AS tot_pedestrians_killed&lt;br&gt;
&lt;code&gt;SUM&lt;/code&gt; &lt;br&gt;
Similar to SQL &lt;code&gt;SUM&lt;/code&gt; aggregate function. &lt;br&gt;
&lt;code&gt;AS&lt;/code&gt; &lt;br&gt;
Give these aggregate results a meaningful label&lt;br&gt;
 &lt;code&gt;$group=year&lt;/code&gt;  and &lt;code&gt;$order=tot_pedestrians_killed&lt;/code&gt;&lt;br&gt;
Similar to the SQL &lt;code&gt;GROUP BY&lt;/code&gt; and &lt;code&gt;ORDER BY&lt;/code&gt;&lt;br&gt;
Returns aggregate rows grouped by the year they occurred.&lt;br&gt;
Sorted having the year with most pedestrian fatalities first&lt;br&gt;
&lt;code&gt;jq .&lt;/code&gt;&lt;br&gt;
This is the most basic &lt;a href="https://stedolan.github.io/jq/"&gt;jq&lt;/a&gt; command&lt;br&gt;
It just prints the JSON output in it’s default “pretty” format&lt;br&gt;
We could have added &lt;code&gt;--silent&lt;/code&gt; to the &lt;code&gt;curl&lt;/code&gt; command or config file, to not print the curl download statistics. &lt;/p&gt;
&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2012 and the current year, 2023,  can be omitted as both years have incomplete data. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Run the previous query minus years 2012 and 2023
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-K&lt;/span&gt; ./.nyc_curlrc   &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$select=date_extract_y(crash_date) AS year, SUM(number_of_pedestrians_killed) AS tot_pedestrians_killed, SUM(number_of_cyclist_killed) AS tot_cyclists_killed'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$where=year not in ("2012", "2023")'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$group=year'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="s1"&gt;'$order=tot_pedestrians_killed DESC, tot_cyclists_killed'&lt;/span&gt;

&lt;span class="o"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2013"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"176"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"11"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2016"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"149"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"18"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2015"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"133"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"15"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2014"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"133"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"20"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2022"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"132"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"18"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2019"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"131"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"31"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2021"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"129"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"19"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2017"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"127"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"27"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2018"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"123"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2020"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"101"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_killed"&lt;/span&gt;:&lt;span class="s2"&gt;"29"&lt;/span&gt;&lt;span class="o"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;$where=year not in ("2012", "2023")&lt;br&gt;
Added a &lt;code&gt;WHERE&lt;/code&gt; clause to omit years 2012 and 2023 from the query&lt;br&gt;
SoQL &lt;a href="https://dev.socrata.com/docs/functions/not_in.html"&gt;not in (...)&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;

&lt;p&gt;Well, it’s not that safe being a pedestrian or cyclist in New York City. Checking the injury count would yield much higher numbers. &lt;/p&gt;
&lt;h3&gt;
  
  
  Run a query to get a yearly total of injured pedestrians and cyclists
&lt;/h3&gt;

&lt;p&gt;Our query string was getting a little bit out of hand and difficult to manage. &lt;br&gt;
I created a dedicated config file, &lt;code&gt;.nyc_ped_cyc_injured_yearly_curlrc&lt;/code&gt;  for our next request.&lt;/p&gt;
&lt;h4&gt;
  
  
  The Config
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; .nyc_ped_cyc_injured_yearly_curlrc 
&lt;span class="c"&gt;# --- NYC Collision Data - Injured List  ---&lt;/span&gt;
get
url &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://data.cityofnewyork.us/resource/h9gi-nx95.json"&lt;/span&gt;
data-urlencode  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$\$&lt;/span&gt;&lt;span class="s2"&gt;app_token=uvwxyz"&lt;/span&gt;
data-urlencode  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=date_extract_y(crash_date) AS year, SUM(number_of_pedestrians_injured) AS tot_pedestrians_injured, SUM(number_of_cyclist_injured) AS tot_cyclists_injured"&lt;/span&gt;
data-urlencode  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;where=year not in ('2012','2023')"&lt;/span&gt;
data-urlencode  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;group=year"&lt;/span&gt; 
data-urlencode  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;order=tot_pedestrians_injured DESC, tot_cyclists_injured DESC"&lt;/span&gt;
silent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  The Query using the config file
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  curl &lt;span class="nt"&gt;--config&lt;/span&gt; ./.nyc_ped_cyc_injured_yearly_curlrc 
&lt;span class="o"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2013"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"11988"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4075"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2017"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"11151"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4889"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2018"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"11123"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4725"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2016"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"11090"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4975"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2014"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"11036"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4000"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2019"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"10568"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4986"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2015"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"10084"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4281"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2022"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"8963"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"5025"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2021"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"7503"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"4961"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
,&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;:&lt;span class="s2"&gt;"2020"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_pedestrians_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"6691"&lt;/span&gt;,&lt;span class="s2"&gt;"tot_cyclists_injured"&lt;/span&gt;:&lt;span class="s2"&gt;"5576"&lt;/span&gt;&lt;span class="o"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;

&lt;p&gt;Looks like the config file worked as expected. While the number of pedestrians injured is declining a little, the number of cyclists injured is going in the opposite direction. &lt;/p&gt;
&lt;h3&gt;
  
  
  Using &lt;a href="https://stedolan.github.io/jq/"&gt;jq&lt;/a&gt; to do additional filtering
&lt;/h3&gt;

&lt;p&gt;Similar to the previous query, extract the yearly totals of injured cyclists. This time we’ll use &lt;a href="https://stedolan.github.io/jq/"&gt;jq&lt;/a&gt; to filter the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; curl &lt;span class="nt"&gt;--config&lt;/span&gt; ./.nyc_ped_cyc_injured_yearly_curlrc &lt;span class="se"&gt;\&lt;/span&gt;
  | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.[] | .year + "," + .tot_cyclists_injured'&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 1n &lt;span class="se"&gt;\&lt;/span&gt;
  | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;, &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Year,CyclistsInjured 
Year  CyclistsInjured
2013  4075
2014  4000
2015  4281
2016  4975
2017  4889
2018  4725
2019  4986
2020  5576
2021  4961
2022  5025
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;This is similar to the previous query except I used  &lt;a href="https://stedolan.github.io/jq/"&gt;jq&lt;/a&gt; to extract the injured cyclist data only from the returned results. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;sort -k 1n&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Sort the Year numerically&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;sort -k 1n&lt;/code&gt;&lt;br&gt;
Sort the Year, numerically&lt;br&gt;
&lt;code&gt;column -t -s, --table-columns=Year,CyclistsInjured&lt;/code&gt;&lt;br&gt;
Add column headers for readability&lt;br&gt;
The &lt;code&gt;jq&lt;/code&gt; command already created comma separated results&lt;/p&gt;

&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;

&lt;p&gt;2020 and 2022 were the worst years for bicyclist injuries. 2020 was a year where cycling became more popular. The injuries dropped a little in 2021, maybe because cyclists got a little scared after the slaughter in 2020. The upward trend may be returning, based on the 2022 results. &lt;/p&gt;

&lt;h3&gt;
  
  
  Get the 10 worst zip codes for collisions in January 2023
&lt;/h3&gt;

&lt;p&gt;Previously I got the [10 worst Zip codes for collisions in February][Get the 10 worst zip codes for collisions in February 2023]. I used some bash commands to fine tune results. Here I will use SoQL to do most of the heavy lifting. &lt;/p&gt;

&lt;h4&gt;
  
  
  Config file &lt;code&gt;.nyc_jan_coll_curlrc&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; .nyc_jan_coll_curlrc 
&lt;span class="c"&gt;# --- NYC Collision Data - January Collisions  ---&lt;/span&gt;
get
url &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://data.cityofnewyork.us/resource/h9gi-nx95.json"&lt;/span&gt;
data-urlencode  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$\$&lt;/span&gt;&lt;span class="s2"&gt;app_token=uvwxyz"&lt;/span&gt;
data-urlencode &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;select=zip_code,count(zip_code) AS collision_count"&lt;/span&gt;
data-urlencode &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;where=crash_date between '2023-01-01' AND '2023-01-31' "&lt;/span&gt;
data-urlencode &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;group=zip_code"&lt;/span&gt;
data-urlencode &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;order=collision_count DESC, zip_code"&lt;/span&gt;
data-urlencode &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;limit=10"&lt;/span&gt;
silent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; curl &lt;span class="nt"&gt;--config&lt;/span&gt; ./.nyc_jan_coll_curlrc &lt;span class="se"&gt;\&lt;/span&gt;
  | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.[] | .zip_code + ", " + .collision_count'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;, &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ZipCode,CollisionCount
ZipCode  CollisionCount
11207     124
11236     83
11208     82
11212     77
11203     69
11385     67
11234     66
11206     64
10002     63
11101     61
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation
&lt;/h4&gt;

&lt;p&gt;Most of this is similar to our earlier request for February stats. This time we are using a new config file &lt;code&gt;.&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
Instead of sorting the results using the bash sort, we sort using the SoQL &lt;code&gt;[$order](https://dev.socrata.com/docs/queries/order.html)&lt;/code&gt;. We get the 10 worst using the &lt;code&gt;$limit&lt;/code&gt; clause. &lt;br&gt;
&lt;code&gt;\$order=collision_count DESC, zip_code&lt;/code&gt;&lt;br&gt;
&lt;a href="https://dev.socrata.com/docs/queries/order.html"&gt;Sort&lt;/a&gt; the collision count from worst to “least worst”. &lt;br&gt;
zip_code ascending sort&lt;br&gt;
&lt;code&gt;$limit=10&lt;/code&gt;&lt;br&gt;
Get the first 10 after the sort using &lt;a href="https://dev.socrata.com/docs/queries/limit.html"&gt;$limit&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Observation
&lt;/h4&gt;

&lt;p&gt;Zip Code &lt;a href="https://www.unitedstateszipcodes.org/11207"&gt;11207&lt;/a&gt;, again emerges as a collision prone area with 124 collisions in January.  That’s 4 collisions a day. Every day is a regular demolition derby day in that part of Brooklyn. &lt;/p&gt;

&lt;h3&gt;
  
  
  Some Perl CLI Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://perlmaven.com/perl-tutorial"&gt;Perl Maven - Great for those new to  Perl&lt;/a&gt;&lt;br&gt;
&lt;a href="https://perldoc.perl.org/perlrun"&gt;Perldocs - perlrun&lt;/a&gt;&lt;br&gt;
&lt;a href="https://catonmat.net/books"&gt;Peteris Krumins has some great e-books&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.perl.com/pub/2004/08/09/commandline.html/"&gt;Dave Cross - From one of his older posts on perl.com&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Some NYC Street Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.socrata.com/foundry/data.cityofnewyork.us/h9gi-nx95"&gt;NYC - Motor Vehicle Collisions - Crashes&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://nyc.streetsblog.org/"&gt;StreetsBlog NYC&lt;/a&gt;&lt;br&gt;
&lt;a href="https://hellgatenyc.com/"&gt;Hellgate NYC - Local NYC News&lt;/a&gt;&lt;br&gt;
&lt;a href="https://elkue.com/"&gt;Liam Quigley - Local Reporter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/_elkue"&gt;More Liam Quigley - Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=jN7mSXMruEo"&gt;These Stupid Trucks are Literally Killing Us – YouTube&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Me
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/austin-kenny-87515311/"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.aibistin.com/"&gt;blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>perl</category>
      <category>soql</category>
      <category>bash</category>
      <category>curl</category>
    </item>
    <item>
      <title>Analyzing New York City Traffic Collisions with Perl One-Liners and Linux</title>
      <dc:creator>Austin</dc:creator>
      <pubDate>Tue, 21 Mar 2023 17:12:33 +0000</pubDate>
      <link>https://forem.com/austin_62/analyzing-new-york-city-traffic-collisions-with-perl-one-liners-and-linux-pnn</link>
      <guid>https://forem.com/austin_62/analyzing-new-york-city-traffic-collisions-with-perl-one-liners-and-linux-pnn</guid>
      <description>&lt;h6&gt;
  
  
  Just when you think it’s safe outside. Here are some statistics relating to traffic collisions in New York City.
&lt;/h6&gt;

&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;NYC publishes vehicle collision data which anyone can access using their API. You can also download this information in standard &lt;a href="https://data.cityofnewyork.us/Public-Safety/Motor-Vehicle-Collisions-Crashes/h9gi-nx95"&gt;CSV (Comma Separated Values) file format&lt;/a&gt;.&lt;br&gt;
The file is fairly large, 420 MB, with almost 2 Million lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;-rw-rw-r--&lt;/span&gt; 1 austin austin 402M Mar  4 20:38 all_motor_vehicle_collision_data.csv
…
bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; all_motor_vehicle_collision_data.csv 
1972886 all_motor_vehicle_collision_data.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Display the first five records of the dataset using &lt;a href="https://ss64.com/bash/head.html"&gt;head&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n5&lt;/span&gt; all_motor_vehicle_collision_data.csv 
CRASH DATE,CRASH TIME,BOROUGH,ZIP CODE,LATITUDE,LONGITUDE,LOCATION,ON STREET NAME,CROSS STREET NAME,OFF STREET NAME,NUMBER OF PERSONS INJURED,NUMBER OF PERSONS KILLED,NUMBER OF PEDESTRIANS INJURED,NUMBER OF PEDESTRIANS KILLED,NUMBER OF CYCLIST INJURED,NUMBER OF CYCLIST KILLED,NUMBER OF MOTORIST INJURED,NUMBER OF MOTORIST KILLED,CONTRIBUTING FACTOR VEHICLE 1,CONTRIBUTING FACTOR VEHICLE 2,CONTRIBUTING FACTOR VEHICLE 3,CONTRIBUTING FACTOR VEHICLE 4,CONTRIBUTING FACTOR VEHICLE 5,COLLISION_ID,VEHICLE TYPE CODE 1,VEHICLE TYPE CODE 2,VEHICLE TYPE CODE 3,VEHICLE TYPE CODE 4,VEHICLE TYPE CODE 5
09/11/2021,2:39,,,,,,WHITESTONE EXPRESSWAY,20 AVENUE,,2,0,0,0,0,0,2,0,Aggressive Driving/Road Rage,Unspecified,,,,4455765,Sedan,Sedan,,,
03/26/2022,11:45,,,,,,QUEENSBORO BRIDGE UPPER,,,1,0,0,0,0,0,1,0,Pavement Slippery,,,,,4513547,Sedan,,,,
06/29/2022,6:55,,,,,,THROGS NECK BRIDGE,,,0,0,0,0,0,0,0,0,Following Too Closely,Unspecified,,,,4541903,Sedan,Pick-up Truck,,,
09/11/2021,9:35,BROOKLYN,11208,40.667202,-73.8665,&lt;span class="s2"&gt;"(40.667202, -73.8665)"&lt;/span&gt;,,,1211      LORING AVENUE,0,0,0,0,0,0,0,0,Unspecified,,,,,4456314,Sedan,,,,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using &lt;a href="https://ss64.com/bash/head.html"&gt;head&lt;/a&gt; to display the first record only
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n1&lt;/span&gt; all_motor_vehicle_collision_data.csv 
CRASH DATE,CRASH TIME,BOROUGH,ZIP CODE,LATITUDE,LONGITUDE,LOCATION,ON STREET NAME,CROSS STREET NAME,OFF STREET NAME,NUMBER OF PERSONS INJURED,NUMBER OF PERSONS KILLED,NUMBER OF PEDESTRIANS INJURED,NUMBER OF PEDESTRIANS KILLED,NUMBER OF CYCLIST INJURED,NUMBER OF CYCLIST KILLED,NUMBER OF MOTORIST INJURED,NUMBER OF MOTORIST KILLED,CONTRIBUTING FACTOR VEHICLE 1,CONTRIBUTING FACTOR VEHICLE 2,CONTRIBUTING FACTOR VEHICLE 3,CONTRIBUTING FACTOR VEHICLE 4,CONTRIBUTING FACTOR VEHICLE 5,COLLISION_ID,VEHICLE TYPE CODE 1,VEHICLE TYPE CODE 2,VEHICLE TYPE CODE 3,VEHICLE TYPE CODE 4,VEHICLE TYPE CODE 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use Perl to list the column names in numerical order
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;bash&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;F&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;an&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$. == 1 &amp;amp;&amp;amp; say $i++ . "\t$_" for @F&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt;  &lt;span class="nv"&gt;all_motor_vehicle_collision_data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;   &lt;span class="nv"&gt;CRASH&lt;/span&gt; &lt;span class="nv"&gt;DATE&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;   &lt;span class="nv"&gt;CRASH&lt;/span&gt; &lt;span class="nv"&gt;TIME&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;   &lt;span class="nv"&gt;BOROUGH&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;   &lt;span class="nv"&gt;ZIP&lt;/span&gt; &lt;span class="nv"&gt;CODE&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;   &lt;span class="nv"&gt;LATITUDE&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;   &lt;span class="nv"&gt;LONGITUDE&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;   &lt;span class="nv"&gt;LOCATION&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;   &lt;span class="nv"&gt;ON&lt;/span&gt; &lt;span class="nv"&gt;STREET&lt;/span&gt; &lt;span class="nv"&gt;NAME&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt;   &lt;span class="nv"&gt;CROSS&lt;/span&gt; &lt;span class="nv"&gt;STREET&lt;/span&gt; &lt;span class="nv"&gt;NAME&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt;   &lt;span class="nv"&gt;OFF&lt;/span&gt; &lt;span class="nv"&gt;STREET&lt;/span&gt; &lt;span class="nv"&gt;NAME&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;PERSONS&lt;/span&gt; &lt;span class="nv"&gt;INJURED&lt;/span&gt;
&lt;span class="mi"&gt;11&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;PERSONS&lt;/span&gt; &lt;span class="nv"&gt;KILLED&lt;/span&gt;
&lt;span class="mi"&gt;12&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;PEDESTRIANS&lt;/span&gt; &lt;span class="nv"&gt;INJURED&lt;/span&gt;
&lt;span class="mi"&gt;13&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;PEDESTRIANS&lt;/span&gt; &lt;span class="nv"&gt;KILLED&lt;/span&gt;
&lt;span class="mi"&gt;14&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;CYCLIST&lt;/span&gt; &lt;span class="nv"&gt;INJURED&lt;/span&gt;
&lt;span class="mi"&gt;15&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;CYCLIST&lt;/span&gt; &lt;span class="nv"&gt;KILLED&lt;/span&gt;
&lt;span class="mi"&gt;16&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;MOTORIST&lt;/span&gt; &lt;span class="nv"&gt;INJURED&lt;/span&gt;
&lt;span class="mi"&gt;17&lt;/span&gt;  &lt;span class="nv"&gt;NUMBER&lt;/span&gt; &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;MOTORIST&lt;/span&gt; &lt;span class="nv"&gt;KILLED&lt;/span&gt;
&lt;span class="mi"&gt;18&lt;/span&gt;  &lt;span class="nv"&gt;CONTRIBUTING&lt;/span&gt; &lt;span class="nv"&gt;FACTOR&lt;/span&gt; &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;19&lt;/span&gt;  &lt;span class="nv"&gt;CONTRIBUTING&lt;/span&gt; &lt;span class="nv"&gt;FACTOR&lt;/span&gt; &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;20&lt;/span&gt;  &lt;span class="nv"&gt;CONTRIBUTING&lt;/span&gt; &lt;span class="nv"&gt;FACTOR&lt;/span&gt; &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="mi"&gt;21&lt;/span&gt;  &lt;span class="nv"&gt;CONTRIBUTING&lt;/span&gt; &lt;span class="nv"&gt;FACTOR&lt;/span&gt; &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="mi"&gt;22&lt;/span&gt;  &lt;span class="nv"&gt;CONTRIBUTING&lt;/span&gt; &lt;span class="nv"&gt;FACTOR&lt;/span&gt; &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="mi"&gt;23&lt;/span&gt;  &lt;span class="nv"&gt;COLLISION_ID&lt;/span&gt;
&lt;span class="mi"&gt;24&lt;/span&gt;  &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="nv"&gt;TYPE&lt;/span&gt; &lt;span class="nv"&gt;CODE&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;25&lt;/span&gt;  &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="nv"&gt;TYPE&lt;/span&gt; &lt;span class="nv"&gt;CODE&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;26&lt;/span&gt;  &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="nv"&gt;TYPE&lt;/span&gt; &lt;span class="nv"&gt;CODE&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="mi"&gt;27&lt;/span&gt;  &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="nv"&gt;TYPE&lt;/span&gt; &lt;span class="nv"&gt;CODE&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="mi"&gt;28&lt;/span&gt;  &lt;span class="nv"&gt;VEHICLE&lt;/span&gt; &lt;span class="nv"&gt;TYPE&lt;/span&gt; &lt;span class="nv"&gt;CODE&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'perl -an -E'&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Split up the column values into array &lt;code&gt;'@F'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-F,'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Specifies a &lt;strong&gt;comma&lt;/strong&gt; field separator.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'$. == 1'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;The Perl special variable &lt;code&gt;'$.'&lt;/code&gt; contains the current line number. &lt;/li&gt;
&lt;li&gt;Display the first line only. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'say $i++ . "\t$_" for @F'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Prints a tab separated counter variable &lt;code&gt;'$i'&lt;/code&gt;, and the corresponding column name, stored in the Perl default variable &lt;code&gt;'$_'&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create a work-file containing the zip-code, injury count, and fatality count. Only get records that include a zip-code and at least one injury or fatality.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3   ZIP CODE
10  NUMBER OF PERSONS INJURED
11  NUMBER OF PERSONS KILLED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Method
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Unfortunately the previous method for splitting a comma delimited file has limitations. It cannot handle fields with embedded commas. The &lt;em&gt;Street Name&lt;/em&gt; fields often have embedded commas which will throw off our column numbering.
&lt;/li&gt;
&lt;li&gt;To get around this we can use &lt;a href="https://metacpan.org/pod/Text::CSV"&gt;Text::CSV&lt;/a&gt;, which has both functional and OO interfaces.  For one-liners, it exports a handy &lt;a href="https://metacpan.org/pod/Text::CSV#csv"&gt;csv function&lt;/a&gt;. From the Text::CSV documentation &lt;code&gt;'my $aoa = csv (in =&amp;gt; "test.csv") or die Text::CSV_XS-&amp;gt;error_diag;''&lt;/code&gt;, it’ll convert the CSV file into an array of arrays.&lt;/li&gt;
&lt;li&gt;I'll modify this example slightly to &lt;code&gt;'csv( in =&amp;gt; $ARGV[0], headers =&amp;gt; qq/skip/ )'&lt;/code&gt;. The @ARGV array contains any input arguments. The first element $ARGV[0] will contain the input CSV file. We don’t need the header row, so it’ll be skipped.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nn"&gt;MText::&lt;/span&gt;&lt;span class="nv"&gt;CSV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$aofa = csv( in =&amp;gt; $ARGV[0], headers =&amp;gt; qq/skip/ ); ( $_-&amp;gt;[3] =~ /^\S+$/ ) &amp;amp;&amp;amp; say qq/$_-&amp;gt;[3],$_-&amp;gt;[10],$_-&amp;gt;[11]/ for @{$aofa}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt;  &lt;span class="nv"&gt;all_motor_vehicle_collision_data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;r&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_zip&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Input file &lt;code&gt;'all_motor_vehicle_collision_data.csv'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'perl -MText::CSV=csv'&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt; Run the perl command with &lt;code&gt;'-M'&lt;/code&gt; switch to load a Perl module.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'Text::CSV=csv'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Export the ‘csv’ function from the &lt;code&gt;'Text::CSV'&lt;/code&gt; module. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'( $_-&amp;gt;[3] =~ /^\S+$/ )'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Use a Regular expression to only process rows that have non-blank data in the &lt;em&gt;ZIP CODE&lt;/em&gt; field. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'say qq/$&lt;em&gt;-&amp;gt;[3],$&lt;/em&gt;-&amp;gt;[10],$_-&amp;gt;[11]/ for @{$aofa}'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Loop through the Array of Arrays &lt;code&gt;'$aofa'&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Print the contents of columns 3,10,11 followed by a line break.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The output is piped &lt;code&gt;'|'&lt;/code&gt; into the Linux sort command. 

&lt;ul&gt;
&lt;li&gt;Sorting on the first field, &lt;em&gt;ZIP CODE&lt;/em&gt; and redirecting, &lt;code&gt;'&amp;gt;'&lt;/code&gt; into a new file, &lt;code&gt;'sorted_injured_killed_by_zip.csv'&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;See the &lt;a href="https://ss64.com/bash/sort.html"&gt;ss64.com site&lt;/a&gt; for more details on the Linux sort command. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The new file has about 1.36 Million lines.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Get a line count with &lt;a href="https://ss64.com/bash/wc.html"&gt;wc&lt;/a&gt;. Display the first 10 records using &lt;a href="https://ss64.com/bash/head.html"&gt;head&lt;/a&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; sorted_injured_killed_by_zip.csv 
1359291 sorted_injured_killed_by_zip.csv
bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n10&lt;/span&gt; sorted_injured_killed_by_zip.csv | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;, &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ZipCode,#Injured,#Killed
ZipCode  &lt;span class="c"&gt;#Injured  #Killed&lt;/span&gt;
11697    4         0
11697    3         0
11697    2         0
11697    2         0
11697    2         0
11697    1         0
11697    1         0
11697    1         0
11697    1         0
11697    1         0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'wc -l'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Counts the number of lines in our new file &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'head -n 10'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Prints out the first 10 lines of the file&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'column -t -s, --table-columns=ZipCode,#Injured,#Killed'&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.man7.org/linux/man-pages/man1/column.1.html"&gt;column&lt;/a&gt;&lt;/li&gt;
&lt;li&gt; &lt;code&gt;'-t'&lt;/code&gt; switch will tell &lt;code&gt;'column'&lt;/code&gt; to print in table format. &lt;/li&gt;
&lt;li&gt; &lt;code&gt;'-s'&lt;/code&gt; switch specifies an input delimiter of ','. &lt;/li&gt;
&lt;li&gt; The output is tabbed. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  List the 10 worst zip codes for injuries
&lt;/h3&gt;

&lt;h4&gt;
  
  
  We can use the output file, sorted_injured_killed_by_zip.csv, from the previous example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@a=split(q/,/,$_);$h{$a[0]} += $a[1]; END{say qq/$_,$h{$_}/ for keys %h}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_zip&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;nr&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;head&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n10&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;column&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nv"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;ZipCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="c1"&gt;#Injured&lt;/span&gt;
&lt;span class="nv"&gt;ZipCode&lt;/span&gt;  &lt;span class="c1"&gt;#Injured&lt;/span&gt;
&lt;span class="mi"&gt;11207&lt;/span&gt;    &lt;span class="mi"&gt;10089&lt;/span&gt;
&lt;span class="mi"&gt;11236&lt;/span&gt;    &lt;span class="mi"&gt;7472&lt;/span&gt;
&lt;span class="mi"&gt;11203&lt;/span&gt;    &lt;span class="mi"&gt;7426&lt;/span&gt;
&lt;span class="mi"&gt;11212&lt;/span&gt;    &lt;span class="mi"&gt;6676&lt;/span&gt;
&lt;span class="mi"&gt;11226&lt;/span&gt;    &lt;span class="mi"&gt;6103&lt;/span&gt;
&lt;span class="mi"&gt;11208&lt;/span&gt;    &lt;span class="mi"&gt;6027&lt;/span&gt;
&lt;span class="mi"&gt;11234&lt;/span&gt;    &lt;span class="mi"&gt;5505&lt;/span&gt;
&lt;span class="mi"&gt;11434&lt;/span&gt;    &lt;span class="mi"&gt;5403&lt;/span&gt;
&lt;span class="mi"&gt;11233&lt;/span&gt;    &lt;span class="mi"&gt;5159&lt;/span&gt;
&lt;span class="mi"&gt;11385&lt;/span&gt;    &lt;span class="mi"&gt;4440&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'@a=split(q/,/,$_);'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;As there are no embedded commas in this file we use the Perl ‘split’ function to break up the 3 CSV fields in each row into array &lt;code&gt;'@a'&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'$h{$a[0]} += $a[1];'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;The first element of each row, &lt;em&gt;ZIP CODE&lt;/em&gt; is used as a key for Hash'&lt;code&gt;%h'&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The value is the accumulated number of injuries for that &lt;em&gt;ZIP CODE&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'$h{$a[0]} += $a[1]'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;We accumulate the second element, $[1], which contains &lt;code&gt;'NUMBER OF PERSONS INJURED'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We can set a value for a Hash key without checking if it exists already. &lt;/li&gt;
&lt;li&gt;This is called Autovivification which is explained nicely by &lt;a href="https://perlmaven.com/autovivification"&gt;The Perl Maven&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'END{say qq/$&lt;em&gt;,$h{$&lt;/em&gt;}/ for keys %h}'&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;'END{}&lt;/code&gt;'block runs after all the rows are processed. &lt;/li&gt;
&lt;li&gt;The keys(Zip Codes) are read and printed along with their corresponding values. &lt;/li&gt;
&lt;li&gt;We could have used Perl to sort the output by the keys, or values. &lt;/li&gt;
&lt;li&gt;I used the Linux &lt;a href="https://ss64.com/bash/sort.html"&gt;sort&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'sort -nr -t, -k 2'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Will perform a numeric sort, descending on the # of people injured. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'head -n10'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Will get the first 10 records printed. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'column -t -s, --table-columns=ZipCode,#Injured'&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;The &lt;code&gt;'columns'&lt;/code&gt; command will produce a prettier output.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'-t'&lt;/code&gt; for table format.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;'-s'&lt;/code&gt; to specify that the fields are comma separated&lt;/li&gt;
&lt;li&gt; &lt;code&gt;'--table-columns''&lt;/code&gt; to add column header names. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;p&gt;Zip code &lt;a href="http://www.neighborhoodlink.com/zip/11207"&gt;11207&lt;/a&gt;, which encompasses East New York, Brooklyn, as well as a small portion of Southern Queens, has a lot of issues with traffic safety. &lt;/p&gt;

&lt;h3&gt;
  
  
  Display the 10 worst zip codes for traffic fatalities
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@a=split(q/,/,$_);$h{$a[0]} += $a[2]; END{say qq/$_,$h{$_}/ for keys %h}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_zip&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;nr&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;head&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n10&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;column&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nv"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;ZipCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="c1"&gt;#Killed&lt;/span&gt;
&lt;span class="nv"&gt;ZipCode&lt;/span&gt;  &lt;span class="c1"&gt;#Killed&lt;/span&gt;
&lt;span class="mi"&gt;11236&lt;/span&gt;    &lt;span class="mi"&gt;44&lt;/span&gt;
&lt;span class="mi"&gt;11207&lt;/span&gt;    &lt;span class="mi"&gt;34&lt;/span&gt;
&lt;span class="mi"&gt;11234&lt;/span&gt;    &lt;span class="mi"&gt;29&lt;/span&gt;
&lt;span class="mi"&gt;11434&lt;/span&gt;    &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;span class="mi"&gt;11354&lt;/span&gt;    &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;span class="mi"&gt;11229&lt;/span&gt;    &lt;span class="mi"&gt;24&lt;/span&gt;
&lt;span class="mi"&gt;11208&lt;/span&gt;    &lt;span class="mi"&gt;24&lt;/span&gt;
&lt;span class="mi"&gt;11206&lt;/span&gt;    &lt;span class="mi"&gt;23&lt;/span&gt;
&lt;span class="mi"&gt;11233&lt;/span&gt;    &lt;span class="mi"&gt;22&lt;/span&gt;
&lt;span class="mi"&gt;11235&lt;/span&gt;    &lt;span class="mi"&gt;21&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;With a few minor adjustments, we got the worst zip codes for traffic collision fatalities&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'$h{$a[0]} += $a[2]'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Accumulate the third element, $[2], which contains &lt;code&gt;'NUMBER OF PERSONS KILLED'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Zip code &lt;a href="http://www.neighborhoodlink.com/zip/11236"&gt;11236&lt;/a&gt;, which includes Canarsie Brooklyn is the worst for traffic fatalities according to this data. 

&lt;ul&gt;
&lt;li&gt;Zip code &lt;strong&gt;11207&lt;/strong&gt; is also very bad for traffic fatalities, as well as being the worst for collision injuries &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;These stats are not 100 percent correct, as out of 1,972,886 collision records, 1,359,291 contained Zip codes. 

&lt;ul&gt;
&lt;li&gt;We have 613,595 records with no zip code, which were not included in the calculations. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Some NYC Borough Stats
&lt;/h3&gt;

&lt;p&gt;Similar to how we created the &lt;code&gt;'sorted_injured_killed_by_zip.csv'&lt;/code&gt;, we can run the following command sequence to create a new file &lt;code&gt;'sorted_injured_killed_by_borough.csv'&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nn"&gt;MText::&lt;/span&gt;&lt;span class="nv"&gt;CSV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$aofa = csv( in =&amp;gt; $ARGV[0], headers =&amp;gt; qq/skip/ ) ; ( $_-&amp;gt;[2] =~ /^\S+/ ) &amp;amp;&amp;amp; say qq/$_-&amp;gt;[2],$_-&amp;gt;[10],$_-&amp;gt;[11]/ for @{$aofa}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt;  &lt;span class="nv"&gt;all_motor_vehicle_collision_data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sort&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="nv"&gt;rn&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="nv"&gt;rn&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="o"&gt;&amp;gt;|&lt;/span&gt;  &lt;span class="nv"&gt;sorted_injured_killed_by_borough&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;The Borough field is the third column, &lt;code&gt;'2   BOROUGH'&lt;/code&gt;, starting from 0, in the &lt;code&gt;'all_motor_vehicle_collision_data.csv'&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'( $_-&amp;gt;[2] =~ /^\S+/ )'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Only get rows which have non blank data in the &lt;em&gt;BOROUGH&lt;/em&gt; field. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'sort -t, -k 3rn -k 2rn -k 1'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;I added some more precise sorting, which is unnecessary except to satisfy my curiosity.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ss64.com/bash/sort.html"&gt;sort&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-k 3rn&lt;/code&gt;''&lt;/li&gt;
&lt;li&gt;Sort by column 3(starting @ 1), which is the fatality count field.&lt;/li&gt;
&lt;li&gt;This is sorted numerically in descending order. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-k 2rn&lt;/code&gt;'' 

&lt;ul&gt;
&lt;li&gt;When equal, the injury count is also sorted numerically, descending. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-k 1'&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;The Borough is sorted in ascending order as a tiebreaker.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Display the first 10 rows of this file.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n10&lt;/span&gt; sorted_injured_killed_by_borough.csv | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;, &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Borough,#Injured,#Killed
Borough        &lt;span class="c"&gt;#Injured  #Killed&lt;/span&gt;
MANHATTAN      12        8
QUEENS         3         5
QUEENS         15        4
QUEENS         1         4
STATEN ISLAND  6         3
BROOKLYN       4         3
BROOKLYN       3         3
QUEENS         3         3
BROOKLYN       1         3
QUEENS         1         3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sanity check if we got all five boroughs
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;, &lt;span class="nt"&gt;-f&lt;/span&gt; 1  sorted_injured_killed_by_borough.csv | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; 
BRONX
BROOKLYN
MANHATTAN
QUEENS
STATEN ISLAND
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'cut -d, -f 1'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://ss64.com/bash/cut.html"&gt;cut&lt;/a&gt; to split the comma delimited file records.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;'-d,'&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Specifies that the cut will comma delimited&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-f 1'&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Get the first field from the &lt;code&gt;cut&lt;/code&gt;, which is the Borough Name. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'sort -u'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Sorts and prints only the unique values to STDOUT&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;We got all 5 New York City boroughs in this file. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Display collision injuries for each borough
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;bash&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@a=split(q/,/,$_);$h{$a[0]} += $a[1]; END{say qq/$_,$h{$_}/ for keys %h}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_borough&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;   &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;nr&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;column&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="nv"&gt;BROOKLYN&lt;/span&gt;       &lt;span class="mi"&gt;137042&lt;/span&gt;
&lt;span class="nv"&gt;QUEENS&lt;/span&gt;         &lt;span class="mi"&gt;105045&lt;/span&gt;
&lt;span class="nv"&gt;BRONX&lt;/span&gt;          &lt;span class="mi"&gt;62880&lt;/span&gt;
&lt;span class="nv"&gt;MANHATTAN&lt;/span&gt;      &lt;span class="mi"&gt;61400&lt;/span&gt;
&lt;span class="nv"&gt;STATEN&lt;/span&gt; &lt;span class="nv"&gt;ISLAND&lt;/span&gt;  &lt;span class="mi"&gt;15659&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Brooklyn emerges as the Borough with the most traffic injuries. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Display collision fatalities by Borough
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;bash&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@a=split(q/,/,$_);$h{$a[0]} += $a[2]; END{say qq/$_,$h{$_}/ for keys %h}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_borough&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;   &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;nr&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;column&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;J&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="sr"&gt;s, --table-columns Borough,#Killed
{
   "table": [
      {
         "borough": "BROOKLYN",&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#killed&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;564&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;},{&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;borough&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;QUEENS&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#killed&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;482&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;},{&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;borough&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;MANHATTAN&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#killed&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;300&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;},{&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;borough&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BRONX&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#killed&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;241&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;},{&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;borough&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;STATEN ISLAND&lt;/span&gt;&lt;span class="p"&gt;",&lt;/span&gt;
         &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#killed&lt;/span&gt;&lt;span class="p"&gt;":&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;88&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Similar to the Injury count by Borough, this counts all fatalities by borough and prints the output in JSON format.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'column -J -s, --table-columns Borough,#Killed'&lt;/code&gt;  Use the &lt;code&gt;'column'&lt;/code&gt; command with the &lt;code&gt;'-J'&lt;/code&gt; switch, for JSON, instead of &lt;code&gt;'-t'&lt;/code&gt; for Table. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  I forgot to mention what date range is involved with this dataset. We can check this with the &lt;a href="https://ss64.com/bash/cut.html"&gt;cut&lt;/a&gt; command.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;, &lt;span class="nt"&gt;-f1&lt;/span&gt; all_motor_vehicle_collision_data.csv | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;/ &lt;span class="nt"&gt;-f3&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Get the date field, &lt;code&gt;'0  CRASH DATE'&lt;/code&gt; which is in &lt;code&gt;'mm/dd/yyyy'&lt;/code&gt; format. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'cut -d, -f '&lt;/code&gt; &lt;code&gt;'all_motor_vehicle_collision_data.csv'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Get the first column/field of data for every row of this CSV file. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-d,'&lt;/code&gt; specifies that we are cutting on the comma delimiters. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-f 1'&lt;/code&gt; specifies that we want the first column/field only&lt;/li&gt;
&lt;li&gt;This is the date in &lt;code&gt;'mm/dd/yyyy'&lt;/code&gt; format. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'cut -d/ -f3'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Will cut the date using &lt;code&gt;'/&lt;/code&gt;’ as the delimiter. &lt;/li&gt;
&lt;li&gt;Grab the third field from this, which is the four digit year. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'sort -u'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;The years are then sorted with duplicates removed. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;The dataset started sometime in 2012 and continues until now, March 2023. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Display the 20 worst days for collisions in NYC
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;, &lt;span class="nt"&gt;-f1&lt;/span&gt; all_motor_vehicle_collision_data.csv | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="nt"&gt;-F&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="s1"&gt;'{print $3 "-" $1 "-" $2}'&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; | &lt;span class="nb"&gt;uniq&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 1nr | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n20&lt;/span&gt; | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="c"&gt;#Collisions,Date&lt;/span&gt;
&lt;span class="c"&gt;#Collisions  Date&lt;/span&gt;
1161        2014-01-21
1065        2018-11-15
999         2017-12-15
974         2017-05-19
961         2015-01-18
960         2014-02-03
939         2015-03-06
911         2017-05-18
896         2017-01-07
884         2018-03-02
883         2017-12-14
872         2016-09-30
867         2013-11-26
867         2018-11-09
857         2017-04-28
851         2013-03-08
851         2016-10-21
845         2017-06-22
845         2018-06-29
841         2018-12-14
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Get a count for all collisions for each date on record &lt;/li&gt;
&lt;li&gt;Display the first 20 with the highest collision count &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ss64.com/bash/cut.html"&gt;cut&lt;/a&gt; 

&lt;ul&gt;
&lt;li&gt;Get the first column from the dataset.&lt;/li&gt;
&lt;li&gt;Pipe this date into the &lt;a href="https://ss64.com/bash/awk.html"&gt;awk&lt;/a&gt; command. &lt;/li&gt;
&lt;li&gt;AWK is a very useful one-liner tool as well as being a full scripting language. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'awk -F '/' '{print $3 "-" $1 "-" $2}'&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'-F '/' '&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Split the date into separate fields using the &lt;code&gt;’/’&lt;/code&gt; as a delimiter. &lt;/li&gt;
&lt;li&gt;$1 contains the month value, $2 contains the day of month and $3 contains the four digit year value. &lt;/li&gt;
&lt;li&gt;These will be printed in the format &lt;code&gt;'”yyyy-mm-dd”&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Dates are then sorted and piped into the &lt;a href="https://ss64.com/bash/uniq.html"&gt;uniq&lt;/a&gt; command. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'uniq -c'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Will create a unique output. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-c'&lt;/code&gt; switch gets a count of all the occurrences for each value. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The output is piped into another sort command, which sorts by the number of occurrences descending. &lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;I’m not sure if there is any explanation for why some days have a lot more collisions than others. Weatherwise, January 21 2014 was a cold day, but otherwise uneventful. November 15 2018 had some snow, but not a horrific snowfall. The clocks went back on November 4, so that wouldn’t be a factor. &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.wunderground.com/history/daily/us/ny/new-york-city/KLGA/date/2014-1-21"&gt;2014-01-21 weather &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.wunderground.com/history/daily/us/ny/new-york-city/KLGA/date/2018-11-15"&gt;2018-11-15 weather&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Display the twenty worst times during the day for collisions
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;, &lt;span class="nt"&gt;-f2&lt;/span&gt; all_motor_vehicle_collision_data.csv | &lt;span class="nb"&gt;sort&lt;/span&gt; | &lt;span class="nb"&gt;uniq&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 1nr | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n20&lt;/span&gt; |column &lt;span class="nt"&gt;-t&lt;/span&gt;  &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="c"&gt;#Collisions,Time&lt;/span&gt;
&lt;span class="c"&gt;#Collisions  Time&lt;/span&gt;
27506       16:00
26940       17:00
26879       15:00
24928       18:00
24667       14:00
22914       13:00
20687       9:00
20641       12:00
20636       19:00
19865       16:30
19264       8:00
19107       10:00
19106       14:30
19010       0:00
18691       11:00
18688       17:30
16646       18:30
16602       20:00
16144       8:30
16008       13:30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;We use the time field, &lt;code&gt;'1   CRASH TIME'&lt;/code&gt;, which is in 24 hour format, 'HH:MM'&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Using the 'actual time' may be a bit too specific. I’ll use the 'hour of day' instead to give a 60 minute time frame.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;, &lt;span class="nt"&gt;-f2&lt;/span&gt; all_motor_vehicle_collision_data.csv | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; : &lt;span class="nt"&gt;-f1&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; | &lt;span class="nb"&gt;uniq&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 1nr | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n10&lt;/span&gt; | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="c"&gt;#Collisions,Hour&lt;/span&gt;
&lt;span class="c"&gt;#Collisions  Hour&lt;/span&gt;
143012      16
139818      17
132443      14
123761      15
122971      18
114555      13
108925      12
108593      8
105206      9
102541      11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Similar to the previous example, except this time the &lt;a href="https://ss64.com/bash/cut.html"&gt;cut&lt;/a&gt; command is used to split the time HH:MM, delimited by &lt;code&gt;':'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'cut -d : -f 1'&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'-d'&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;The 'cut' delimiter is ':'&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'-f 1'&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Grab the first field, 'HH' of the 'HH:MM'. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Use something like the &lt;a href="https://ss64.com/bash/printf.html"&gt;printf&lt;/a&gt; command to append &lt;code&gt;':00'&lt;/code&gt; to those hours. &lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;p&gt;As you would expect, most collisions happen during rush hour. &lt;/p&gt;

&lt;h3&gt;
  
  
  Display the worst years for collisions
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;, &lt;span class="nt"&gt;-f1&lt;/span&gt; all_motor_vehicle_collision_data.csv | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="nt"&gt;-f3&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; | &lt;span class="nb"&gt;uniq&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; 1nr | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n10&lt;/span&gt; | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="c"&gt;#Collisions,Year&lt;/span&gt;
&lt;span class="c"&gt;#Collisions  Year&lt;/span&gt;
231564       2018
231007       2017
229831       2016
217694       2015
211486       2019
206033       2014
203734       2013
112915       2020
110546       2021
103745       2022
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;We use the first column, &lt;code&gt;'0 CRASH DATE'&lt;/code&gt; again&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'cut -d '/' -f3'&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;Extracts the &lt;code&gt;'yyyy'&lt;/code&gt; from the &lt;code&gt;'mm/dd/yyyy'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Some improvement seen in 2020, 2021 and 2022, if you can believe the data. &lt;/li&gt;
&lt;li&gt;One unscientific observation here is that the NYPD may have been much less vigilant in the past few years than they were prior to Commissioner Raymond Kelly and his successors. &lt;/li&gt;
&lt;li&gt;Also, by only printing out the worst 10 years, partial years 2012 and 2023 were excluded. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  For a comparison. See how many people were injured or killed in traffic collisions.
&lt;/h3&gt;

&lt;h5&gt;
  
  
  First create a work file, &lt;code&gt;'sorted_injured_killed_by_year.csv'&lt;/code&gt;, with three columns, Year, Injured count and Fatality count
&lt;/h5&gt;

&lt;p&gt;We need the &lt;a href="https://metacpan.org/pod/Text::CSV"&gt;Text::CSV&lt;/a&gt; Perl module here due to those embedded commas in earlier fields.  Below are the three fields needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0   CRASH DATE
10  NUMBER OF PERSONS INJURED
11  NUMBER OF PERSONS KILLED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;bash&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nn"&gt;MText::&lt;/span&gt;&lt;span class="nv"&gt;CSV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$aofa = csv( in =&amp;gt; $ARGV[0], headers =&amp;gt; qq/skip/ ); ($_-&amp;gt;[10] || $_-&amp;gt;[11]) &amp;amp;&amp;amp; say substr($_-&amp;gt;[0],6,4) . qq/,$_-&amp;gt;[10],$_-&amp;gt;[11]/ for @{$aofa}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="nv"&gt;all_motor_vehicle_collision_data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_year&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Check out the work file we just created
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; sorted_injured_killed_by_year.csv 
433081 sorted_injured_killed_by_year.csv

bash &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n10&lt;/span&gt; sorted_injured_killed_by_year.csv | column &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;, &lt;span class="nt"&gt;--table-columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Year,#Injured,#Killed
Year  &lt;span class="c"&gt;#Injured  #Killed&lt;/span&gt;
2012  0         1
2012  0         1
2012  0         1
2012  0         1
2012  0         1
2012  0         1
2012  0         1
2012  0         1
2012  0         1
2012  0         1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Worst years for collision injuries
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@a=split(q/,/,$_);$h{$a[0]} += $a[1]; END{say qq/$_,  $h{$_}/ for sort {$h{$b} &amp;lt;=&amp;gt; $h{$a} } keys %h}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_year&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;head&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n10&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="nv"&gt;column&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nv"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;Year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="c1"&gt;#Injured &lt;/span&gt;
&lt;span class="nv"&gt;Year&lt;/span&gt;  &lt;span class="c1"&gt;#Injured&lt;/span&gt;
&lt;span class="mi"&gt;2018&lt;/span&gt;    &lt;span class="mi"&gt;61941&lt;/span&gt;
&lt;span class="mi"&gt;2019&lt;/span&gt;    &lt;span class="mi"&gt;61389&lt;/span&gt;
&lt;span class="mi"&gt;2017&lt;/span&gt;    &lt;span class="mi"&gt;60656&lt;/span&gt;
&lt;span class="mi"&gt;2016&lt;/span&gt;    &lt;span class="mi"&gt;60317&lt;/span&gt;
&lt;span class="mi"&gt;2013&lt;/span&gt;    &lt;span class="mi"&gt;55124&lt;/span&gt;
&lt;span class="mi"&gt;2022&lt;/span&gt;    &lt;span class="mi"&gt;51883&lt;/span&gt;
&lt;span class="mi"&gt;2021&lt;/span&gt;    &lt;span class="mi"&gt;51780&lt;/span&gt;
&lt;span class="mi"&gt;2015&lt;/span&gt;    &lt;span class="mi"&gt;51358&lt;/span&gt;
&lt;span class="mi"&gt;2014&lt;/span&gt;    &lt;span class="mi"&gt;51223&lt;/span&gt;
&lt;span class="mi"&gt;2020&lt;/span&gt;    &lt;span class="mi"&gt;44615&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;This is similar to how we got the Zip Code and Borough data previously. &lt;/li&gt;
&lt;li&gt;This time the Perl sort is used instead of the Linux sort. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'END{say qq/$_,  $h{$_}/ for sort {$h{$b} &amp;lt;=&amp;gt; $h{$a} } keys %h}'&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;'for'&lt;/code&gt; statement loops through the &lt;code&gt;'%h'&lt;/code&gt; hash keys(years). &lt;/li&gt;
&lt;li&gt;The corresponding Hash values(Injured count), are sorted in descending order.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'sort {$h{$b} &amp;lt;=&amp;gt; $h{$a} }'&lt;/code&gt;. 

&lt;ul&gt;
&lt;li&gt;$a and $b are default Perl sort variables.&lt;/li&gt;
&lt;li&gt;Rearranged it to &lt;code&gt;'sort {$h{$a} &amp;lt;=&amp;gt; $h{$b} }'&lt;/code&gt;, to sort the injury count in ascending order. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;p&gt;While the collision count may have gone down, there isn't any real corresponding downward trend in injuries. &lt;/p&gt;

&lt;h4&gt;
  
  
  The worst years for collision fatalities.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;bash&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;perl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@a=split(q/,/,$_);$h{$a[0]} += $a[2]; END{say qq/$_,  $h{$_}/ for sort {$h{$b} &amp;lt;=&amp;gt; $h{$a} } keys %h}&lt;/span&gt;&lt;span class="p"&gt;'&lt;/span&gt; &lt;span class="nv"&gt;sorted_injured_killed_by_year&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;head&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;n10&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="nv"&gt;column&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nv"&gt;table&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;Year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="c1"&gt;#Killed&lt;/span&gt;
&lt;span class="nv"&gt;Year&lt;/span&gt;  &lt;span class="c1"&gt;#Killed&lt;/span&gt;
&lt;span class="mi"&gt;2013&lt;/span&gt;    &lt;span class="mi"&gt;297&lt;/span&gt;
&lt;span class="mi"&gt;2021&lt;/span&gt;    &lt;span class="mi"&gt;294&lt;/span&gt;
&lt;span class="mi"&gt;2022&lt;/span&gt;    &lt;span class="mi"&gt;285&lt;/span&gt;
&lt;span class="mi"&gt;2020&lt;/span&gt;    &lt;span class="mi"&gt;268&lt;/span&gt;
&lt;span class="mi"&gt;2014&lt;/span&gt;    &lt;span class="mi"&gt;262&lt;/span&gt;
&lt;span class="mi"&gt;2017&lt;/span&gt;    &lt;span class="mi"&gt;256&lt;/span&gt;
&lt;span class="mi"&gt;2016&lt;/span&gt;    &lt;span class="mi"&gt;246&lt;/span&gt;
&lt;span class="mi"&gt;2019&lt;/span&gt;    &lt;span class="mi"&gt;244&lt;/span&gt;
&lt;span class="mi"&gt;2015&lt;/span&gt;    &lt;span class="mi"&gt;243&lt;/span&gt;
&lt;span class="mi"&gt;2018&lt;/span&gt;    &lt;span class="mi"&gt;231&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Explanation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Slightly modified version of the injury by year count. &lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Observation
&lt;/h5&gt;

&lt;p&gt;Same as with the injuries count. There isn't any real corresponding downward trend in traffic collision fatalities. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;There’s lots more work that can be done to extract meaningful information from this dataset.&lt;br&gt;&lt;br&gt;
What’s clear to me, is that all the political rhetoric and money poured into &lt;a href="https://www.nyc.gov/content/visionzero/pages/"&gt;Vision Zero&lt;/a&gt; has yielded little in terms of results. &lt;br&gt;
Most of the solutions are obvious from a logical point of view, but not a political point of view. I walk and cycle these streets and know how dangerous it is to cross at the “designated” crosswalks when cars and trucks are turning in on top of you. Cycling in NYC is even worse.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some sugggested solutions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Delayed green lights co cars cars don't turn in on pedestrians at crosswalks. &lt;/li&gt;
&lt;li&gt;Much higher tax and registraton fees for giant SUV's and pickup trucks. The don’t belong in the city. &lt;/li&gt;
&lt;li&gt;Better bike lanes, instead of meaningless lines painted on the road.

&lt;ul&gt;
&lt;li&gt; Many bike lanes are used as convenient parking for NYPD and delivery vehicles. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Basic enforcement of traffic laws, which isn't being done now. 

&lt;ul&gt;
&lt;li&gt;Drivers ignore red lights, speed limits, noise restrictions etc. when they know they aren't being enforced. &lt;/li&gt;
&lt;li&gt;Driving while texting or yapping on the phone is the norm, not the exception. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Drastically improve public transit, especially in areas not served by the subway system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Some Perl CLI Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://perldoc.perl.org/perlrun"&gt;Perldocs - perlrun&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://catonmat.net/books"&gt;Peteris Krumins has some great e-books&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.perl.com/pub/2004/08/09/commandline.html/"&gt;Dave Cross - From one of his older posts on perl.com&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Some NYC Street Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://nyc.streetsblog.org/"&gt;StreetsBlog NYC&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hellgatenyc.com/"&gt;Hellgate NYC - Local NYC News&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://elkue.com/"&gt;Liam Quigley - Local Reporter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/_elkue"&gt;More Liam Quigley - Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=jN7mSXMruEo"&gt;These Stupid Trucks are Literally Killing Us - YouTube&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Me
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/austin-kenny-87515311/"&gt;Linkedin&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.aibistin.com/"&gt;My Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>perl</category>
      <category>linux</category>
      <category>data</category>
      <category>traffic</category>
    </item>
  </channel>
</rss>
