<?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: Importing multiple CSV files using Python in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174232#M55194</link>
    <description>&lt;P&gt;Of course read &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119500"&gt;@KimberlyGarbade&lt;/a&gt;'s answer but also you might want to know the error you are getting is because you used backslashes in Line 2.&lt;/P&gt;&lt;P&gt;You could either put a "r" in front like this:&amp;nbsp; &amp;nbsp; r"C:\data\"&amp;nbsp; &amp;nbsp; or use regular slashes "C:/data/"&lt;/P&gt;&lt;P&gt;There is one more way that might confuse you --&amp;nbsp; &amp;nbsp;"C:\\"&amp;nbsp; the first \ says to give the next character special treatment.&amp;nbsp; Often it's used for "\t" which means "insert a TAB"&lt;/P&gt;&lt;P&gt;Once you fix that and run it again, I bet you get an error about in_data being a list and it wants to be a string in line 6. You have to feed it one filename at a time like: in_data = r"C:\data\foo.csv"&lt;/P&gt;&lt;P&gt;and the second arg "fillter" needs to be the name of the output, it would be great if you could feed it a wildcard but pretty much nothing in arcpy is that convenient. You'd have to do something outside arcpy,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119500"&gt;@KimberlyGarbade&lt;/a&gt;&amp;nbsp;did it a good way using "glob" which can take wildcards and return filenames.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/449202"&gt;@fred7&lt;/a&gt;&amp;nbsp;are you trying to generate one feature class as output or 30?&lt;/P&gt;</description>
    <pubDate>Mon, 16 May 2022 16:24:43 GMT</pubDate>
    <dc:creator>Brian_Wilson</dc:creator>
    <dc:date>2022-05-16T16:24:43Z</dc:date>
    <item>
      <title>Importing multiple CSV files using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174176#M55190</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;I have 30 csv files with similar structure. I have used to import CSV files manually from Menu -&amp;gt; Map -&amp;gt; Add Data -&amp;gt; XY Point Data, where I choose the CSV file and press "Run."&lt;BR /&gt;(X Field and Y Field are recognized/filled automatically from CSV - latitude, longitude). Z field is left empty.&lt;/P&gt;&lt;P&gt;How can I do this in Python?&lt;BR /&gt;Here are some of my thoughts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
in_data = ["C:\data\"]
filter = "*.csv"
z_value = ""

arcpy.management.XYTableToPoint(in_data, filter,"longitude", "latitude",z_value,arcpy.SpatialReference(4759, 115700))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Throws an error - SyntaxError: EOL while scanning string literal (&amp;lt;string&amp;gt;, line 2)&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 14:30:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174176#M55190</guid>
      <dc:creator>fred7</dc:creator>
      <dc:date>2022-05-16T14:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple CSV files using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174223#M55193</link>
      <description>&lt;P&gt;If I understand your question correctly something like this should work:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import os
import glob
import pandas as pd
#concatenate your files (lines 13-22)
#Set your workspace where you are going to create the output feature class
arcpy.env.workspace = r"D:\Test\ESRI Community Helper\ESRI Community Helper.gdb"
#The path to your .csv files goes here
os.chdir(r"D:\Test\CSVTestDirector")
extension = 'csv'
csvAllFiles = [i for i in glob.glob('*.{}'.format(extension))]
#combine all files in the list
combined_csv = pd.concat([pd.read_csv(f) for f in csvAllFiles])
#export to csv
combined_csv.to_csv( "AllCSVs.csv", index=False, encoding='utf-8-sig')

#Create feature class from concatinated csv files
#Update your .csv file path, output file name, "X","Y" column names, and SpatialReference here
arcpy.management.XYTableToPoint(r"D:\Test\CSVTestDirector\AllCSVs.csv", "outputCSV","X","Y","",arcpy.SpatialReference(4759, 115700))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 16:08:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174223#M55193</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-05-16T16:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple CSV files using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174232#M55194</link>
      <description>&lt;P&gt;Of course read &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119500"&gt;@KimberlyGarbade&lt;/a&gt;'s answer but also you might want to know the error you are getting is because you used backslashes in Line 2.&lt;/P&gt;&lt;P&gt;You could either put a "r" in front like this:&amp;nbsp; &amp;nbsp; r"C:\data\"&amp;nbsp; &amp;nbsp; or use regular slashes "C:/data/"&lt;/P&gt;&lt;P&gt;There is one more way that might confuse you --&amp;nbsp; &amp;nbsp;"C:\\"&amp;nbsp; the first \ says to give the next character special treatment.&amp;nbsp; Often it's used for "\t" which means "insert a TAB"&lt;/P&gt;&lt;P&gt;Once you fix that and run it again, I bet you get an error about in_data being a list and it wants to be a string in line 6. You have to feed it one filename at a time like: in_data = r"C:\data\foo.csv"&lt;/P&gt;&lt;P&gt;and the second arg "fillter" needs to be the name of the output, it would be great if you could feed it a wildcard but pretty much nothing in arcpy is that convenient. You'd have to do something outside arcpy,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119500"&gt;@KimberlyGarbade&lt;/a&gt;&amp;nbsp;did it a good way using "glob" which can take wildcards and return filenames.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/449202"&gt;@fred7&lt;/a&gt;&amp;nbsp;are you trying to generate one feature class as output or 30?&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 16:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174232#M55194</guid>
      <dc:creator>Brian_Wilson</dc:creator>
      <dc:date>2022-05-16T16:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple CSV files using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174243#M55196</link>
      <description>&lt;P&gt;Some things you wrote are confusing especially to beginners, like this&lt;/P&gt;&lt;LI-CODE lang="c"&gt;csvAllFiles = [i for i in glob.glob('*.{}'.format(extension))]&lt;/LI-CODE&gt;&lt;P&gt;This line says "use the glob function to look for files matching the pattern *.csv and return a list, then iterate over the list and make another list."&amp;nbsp; &amp;nbsp;so you could just write this&lt;/P&gt;&lt;LI-CODE lang="c"&gt;csvAllFiles = glob.glob("*.csv")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and again with line 13 it could just be&lt;/P&gt;&lt;LI-CODE lang="c"&gt;combined_csv = pd.concat(csvAllFiles)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You could combine them into one line but personally I llke to add a test, actually lots and lots of tests &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;after the "glob" line I would do&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if len(csvAllFiles)==0:
  print("I did not find any CSV files! Quitting.")
  exit(0)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 May 2022 16:41:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174243#M55196</guid>
      <dc:creator>Brian_Wilson</dc:creator>
      <dc:date>2022-05-16T16:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple CSV files using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174360#M55204</link>
      <description>&lt;P&gt;Thank you all for the answers! I am trying to get the script work.&lt;BR /&gt;&lt;BR /&gt;I have csv files for 30 different days. Each day we have measured water surface parametes (salinity, temperature, turbidity, chlorophyll) in different points.&lt;BR /&gt;I have to make interpolation maps (Kriging) for each parameter every 30 days.&lt;/P&gt;&lt;P&gt;I was thinking that I use Python to import all 30 files as&amp;nbsp;&lt;SPAN&gt;XY Point Data (and get points on map).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then manually interpolate those points with Kriging (using one parameter eg salinity) for each 30 day.&lt;BR /&gt;After that use the same imported points and interpolate another parameter (eg temperature). And so on.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 21:56:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174360#M55204</guid>
      <dc:creator>fred7</dc:creator>
      <dc:date>2022-05-16T21:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple CSV files using Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174455#M55215</link>
      <description>&lt;P&gt;Hi again, I was able to import 30 csv files using Geoprocessing -&amp;gt; XY Table To Point -&amp;gt; right click "Batch."&lt;BR /&gt;I choosed all CSV files and pressed "Run" and got those points on map.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 07:10:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/importing-multiple-csv-files-using-python/m-p/1174455#M55215</guid>
      <dc:creator>fred7</dc:creator>
      <dc:date>2022-05-17T07:10:48Z</dc:date>
    </item>
  </channel>
</rss>

