<?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>question Re: Combine csv files  with one header in a csv file in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123689#M55441</link>
    <description>&lt;P&gt;You can do that by passing a list of csv files in csv&lt;/P&gt;&lt;PRE&gt;df = sqlContext.read.load("com.databricks.spark.csv").option("header","true").option("inferSchema","true").load(["/tmp/test_1.csv","/tmp/test_2.csv","/tmp/test_3.csv"])&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Nov 2018 17:05:03 GMT</pubDate>
    <dc:creator>prakash1</dc:creator>
    <dc:date>2018-11-08T17:05:03Z</dc:date>
    <item>
      <title>Combine csv files  with one header in a csv file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123685#M55437</link>
      <description>&lt;P&gt;Hi friends I have csv files  in local file system , they all have the same header i want to get one csv file with this header , is there a solution using spark-csv or any thing else nwant to loop and merge them any solution please and get a final csv file , using spark &lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 16:51:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123685#M55437</guid>
      <dc:creator>zoro07500</dc:creator>
      <dc:date>2017-02-24T16:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Combine csv files  with one header in a csv file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123686#M55438</link>
      <description>&lt;P&gt;
	Assumption: all files have the same columns and in each file the first line is the header&lt;/P&gt;&lt;P&gt;
	This is a solution in PySpark&lt;/P&gt;&lt;P&gt;
	I load every file via "com.databricks.spark.csv" class respecting header and inferring schema&lt;/P&gt;&lt;P&gt;
	Then I use python reduce to union them all&lt;/P&gt;
&lt;PRE&gt;from functools import reduce
files = ["/tmp/test_1.csv", "/tmp/test_2.csv", "/tmp/test_3.csv"]
df = reduce(lambda x,y: x.unionAll(y), 
            [sqlContext.read.format('com.databricks.spark.csv')
                       .load(f, header="true", inferSchema="true") 
             for f in files])
df.show()
&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2017 17:30:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123686#M55438</guid>
      <dc:creator>bwalter1</dc:creator>
      <dc:date>2017-02-24T17:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Combine csv files  with one header in a csv file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123687#M55439</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/452/bwalter.html" nodeid="452"&gt;@Bernhard Walter&lt;/A&gt; &lt;/P&gt;&lt;P&gt;Thanks a lot but can you do it in scala language please it is so kind of you thanks&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 17:35:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123687#M55439</guid>
      <dc:creator>zoro07500</dc:creator>
      <dc:date>2017-02-24T17:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Combine csv files  with one header in a csv file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123688#M55440</link>
      <description>&lt;P&gt;I like &lt;A rel="user" href="https://community.cloudera.com/users/452/bwalter.html" nodeid="452"&gt;@Bernhard Walter&lt;/A&gt;'s PySpark solution! Here's another way to do it using Scala:&lt;/P&gt;&lt;PRE&gt;import org.apache.spark.sql.SQLContext 

val sqlContext = new SQLContext(sc) 

val df = sqlContext.read.format("com.databricks.spark.csv").option("header", "true").option("inferSchema", "true").load("/tmp/test_1.csv","/tmp/test_2.csv","/tmp/test_3.csv") 

df.show()&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2017 01:35:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123688#M55440</guid>
      <dc:creator>dzaratsian</dc:creator>
      <dc:date>2017-02-25T01:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Combine csv files  with one header in a csv file</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123689#M55441</link>
      <description>&lt;P&gt;You can do that by passing a list of csv files in csv&lt;/P&gt;&lt;PRE&gt;df = sqlContext.read.load("com.databricks.spark.csv").option("header","true").option("inferSchema","true").load(["/tmp/test_1.csv","/tmp/test_2.csv","/tmp/test_3.csv"])&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Nov 2018 17:05:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Combine-csv-files-with-one-header-in-a-csv-file/m-p/123689#M55441</guid>
      <dc:creator>prakash1</dc:creator>
      <dc:date>2018-11-08T17:05:03Z</dc:date>
    </item>
  </channel>
</rss>

