<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: loop through headers in csv file and make shapefiles based on dates in the header in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-through-headers-in-csv-file-and-make/m-p/1219407#M65755</link>
    <description>&lt;P&gt;I have a few questions&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You use a variable called all_csv but I don't see it defined.&amp;nbsp; Perhaps it's defined above where you copied and pasted?&lt;/LI&gt;&lt;LI&gt;Your usecols expression appears to be filtering&amp;nbsp;&lt;EM&gt;out&lt;/EM&gt; the columns that you need.&amp;nbsp; For instance, I can see that you need the Long and Lat fields, but the DataFrame creation appears to contain fields that do not include Long and Lat&lt;/LI&gt;&lt;LI&gt;A sample CSV would be nice, even if it contained a header row and two features&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 15:49:05 GMT</pubDate>
    <dc:creator>RogerDunnGIS</dc:creator>
    <dc:date>2022-10-06T15:49:05Z</dc:date>
    <item>
      <title>loop through headers in csv file and make shapefiles based on dates in the header</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-headers-in-csv-file-and-make/m-p/1211289#M65524</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am unable to figure a way out how to create a shapefile after looping through the csv files and matching the headers (dates in format Oct11/2018). Each shapefile should have all the fields with the date that matches the header. In this way I want to create multiple shapefiles for each single date and with the date as the name of the shapefile.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
import numpy as np
import glob
import csv
import arcpy,os
from arcpy import env

arcpy.env.workspace = "D:/datasets/regression_interpolation_rasters/gst_airtemp/excels_shapefiles"
path = "D:/datasets/regression_interpolation_rasters/gst_airtemp/excels_shapefiles"
#arcpy.env.overwriteOutput = True
scratchGDB = arcpy.env.scratchGDB
csvlist = glob.glob(path + "/*.csv")

headers_dict = dict()
for filename in all_csv:
    #print(filename)##15
    df = pd.read_csv(filename, index_col= None, header=0, parse_dates = True, usecols=lambda x: x not in ["Stat_name","Name", "Altitude", "Lat", "Long"])
    #print(df)
    #print(type(df))
    headers_dict[filename] = df.columns
    #print(type(headers_dict))

for csvfile in csvlist:
    #print(csvfile)##24
    headers = pd.read_csv(csvfile, index_col= None, header=0, parse_dates = True, usecols=lambda x: x not in ["Stat_name","Name", "Altitude", "Lat", "Long"])
    #print(headers)
    #print(type(headers))

    
    headers_dict = headers
    arcpy.TableToTable_conversion(csvfile, scratchGDB, "CSV")
    outLayer = "date"
    #print(table)
    #print(type(table))
    spatialreference = arcpy.SpatialReference(32632)
    arcpy.MakeXYEventLayer_management(os.path.join(scratchGDB, "CSV"), "Long","Lat",outLayer,spatialreference,"Altitude")
    arcpy.FeatureClassToShapefile_conversion(outLayer, path) 
    arcpy.MakeFeatureLayer_management(outLayer, "outLayer_lyr") 
    arcpy.SelectLayerByAttribute_management("outLayer_lyr", "NEW_SELECTION") 
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is one example using an image&lt;/P&gt;&lt;P&gt;This is the csv file converted to shapefile with all the dates&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VasudhaChaturvedi_1-1663147185972.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51130i0804678083D49F82/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VasudhaChaturvedi_1-1663147185972.png" alt="VasudhaChaturvedi_1-1663147185972.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Converted shapefile I want&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VasudhaChaturvedi_4-1663148447389.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51135iB40F736D70AE0467/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VasudhaChaturvedi_4-1663148447389.png" alt="VasudhaChaturvedi_4-1663148447389.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VasudhaChaturvedi_3-1663147592285.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51134iD6664107FC77B84C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VasudhaChaturvedi_3-1663147592285.png" alt="VasudhaChaturvedi_3-1663147592285.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 09:41:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-headers-in-csv-file-and-make/m-p/1211289#M65524</guid>
      <dc:creator>VasudhaChaturvedi</dc:creator>
      <dc:date>2022-09-14T09:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: loop through headers in csv file and make shapefiles based on dates in the header</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-headers-in-csv-file-and-make/m-p/1219407#M65755</link>
      <description>&lt;P&gt;I have a few questions&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You use a variable called all_csv but I don't see it defined.&amp;nbsp; Perhaps it's defined above where you copied and pasted?&lt;/LI&gt;&lt;LI&gt;Your usecols expression appears to be filtering&amp;nbsp;&lt;EM&gt;out&lt;/EM&gt; the columns that you need.&amp;nbsp; For instance, I can see that you need the Long and Lat fields, but the DataFrame creation appears to contain fields that do not include Long and Lat&lt;/LI&gt;&lt;LI&gt;A sample CSV would be nice, even if it contained a header row and two features&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 15:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-headers-in-csv-file-and-make/m-p/1219407#M65755</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2022-10-06T15:49:05Z</dc:date>
    </item>
  </channel>
</rss>

