<?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: write from a Dataframe to a CSV file,  CSV file is blank in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28606#M20386</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;In python they have something like [-1] that will save the file in the previous folder, do we have this in Scala?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Sep 2018 20:06:26 GMT</pubDate>
    <dc:creator>Nik</dc:creator>
    <dc:date>2018-09-04T20:06:26Z</dc:date>
    <item>
      <title>write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28597#M20377</link>
      <description>&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;Hi&lt;/P&gt; 
&lt;P&gt;i am reading from a text file from a blob&lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;val sparkDF = spark.read.format(file_type)
.option("header", "true")
.option("inferSchema", "true")
.option("delimiter", file_delimiter)
.load(wasbs_string + "/" + PR_FileName)
&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;Then i test my Dataframe &lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;sparkDF.createOrReplaceTempView("tblLookupTable")
//sparkDF.show()
//sparkDF.show(10)
//sparkDF.take(5)
&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;do some other things like&lt;/P&gt;val sqlDF = spark.sql("SELECT * FROM tblLookupTable") //sqlDF.printSchema() //sqlDF.show(1000) 
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;up to this point everything works finally i want to write it to another blob&lt;/P&gt; 
&lt;P&gt;it works but the csv file is empty, why ????? can someone help&lt;/P&gt;sqlDF.write.format("com.databricks.spark.csv") .option("header", "true") .option("inferSchema", "true") .option("delimiter", "|") .save("wasbs: 
//MyRootName@MyBlobName.blob.core.windows.net/MyPathName/mydata.csv") 
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;it works with no data , and yes it does create the temp folder "mydata.csv" and the file mydata.csv&lt;/P&gt; 
&lt;P&gt;but the file has no Headers and no data .&lt;/P&gt; 
&lt;P&gt;thanks&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:03:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28597#M20377</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-04T17:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28598#M20378</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt; Hey Nik,&lt;/P&gt;
&lt;P&gt; Can you do a file listing on that directory ".../MyPathName/mydata.csv/" and post the names of the files here?&lt;/P&gt;
&lt;P&gt; Your data should be located in the CSV file(s) that begin with "part-00000-tid-xxxxx.csv", with each partition in a separate csv file unless when writing the file, you specify with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;sqlDF.coalesce(1).write.format("com.databricks.spark.csv")...&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:59:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28598#M20378</guid>
      <dc:creator>User16829051266</dc:creator>
      <dc:date>2018-09-04T17:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28599#M20379</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I only have one file in the folder "MyFolder" its a simple read me file&lt;/P&gt;
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;sqlDF.write.format(file_type) .option("header", "true") .option("inferSchema", "true") .option("delimiter", "|") .save("wasbs://MyContainer@MyBlob.blob.core.windows.net/MyFolder/mydata.csv")&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;..i do not see "part-00000-tid-xxxxx.csv" , by the way i am saving into a blob folder, as i had mentioned the file is getting created in the blob folder but with no data&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:13:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28599#M20379</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-04T19:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28600#M20380</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Can you look in folder "mydata.csv"? In this context mydata.csv should be a folder, not a file.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:32:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28600#M20380</guid>
      <dc:creator>User16829051266</dc:creator>
      <dc:date>2018-09-04T19:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28601#M20381</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;It would be helpful to provide a screenshot of your Blob storage to see what your directory looks like.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:40:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28601#M20381</guid>
      <dc:creator>User16829051266</dc:creator>
      <dc:date>2018-09-04T19:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28602#M20382</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;ok , let me run it first&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:46:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28602#M20382</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-04T19:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28603#M20383</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Yes you are right the file in the root is empty but the file with the name ...&lt;/P&gt;
&lt;P&gt;&lt;B&gt;part-00001-tid-4180453911607372978-2f22edb4-c9ca-47c8-8791-81cb9b71824c-8-c000.csv&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;has the data, BUT WHY??????&lt;/P&gt;
&lt;P&gt;I asked the function to save into ....&lt;/P&gt;
&lt;P&gt;wasbs://MyContainer@MyBlob.blob.core.windows.net/MyFolder/mydata.csv&lt;/P&gt;
&lt;P&gt;do you know another way to save the data in the right folder? and the right file?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:51:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28603#M20383</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-04T19:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28604#M20384</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I tried with &lt;/P&gt;
&lt;P&gt;sqlDF.write.format("com.databricks.spark.csv")&lt;/P&gt;
&lt;P&gt;same thing the csv file is empty&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:57:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28604#M20384</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-04T19:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28605#M20385</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0693f000007OrnHAAS"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2527iA106D46DB8F0C4B1/image-size/large?v=v2&amp;amp;px=999" role="button" title="0693f000007OrnHAAS" alt="0693f000007OrnHAAS" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;screenshot&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 20:04:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28605#M20385</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-04T20:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28606#M20386</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;In python they have something like [-1] that will save the file in the previous folder, do we have this in Scala?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 20:06:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28606#M20386</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-04T20:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28607#M20387</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I have noticed that the data have been split into to 2 CSV file in the folder, WHY is that??????&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 02:16:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28607#M20387</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-05T02:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28608#M20388</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hi, I have the same issue about what Nik has been facing. what could be the solution and i am expecting one csv file rather than containing a folder with unknown files?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 18:47:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28608#M20388</guid>
      <dc:creator>lalithagutthi</dc:creator>
      <dc:date>2018-09-11T18:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28609#M20389</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Can i have update on this? I had same issue and not sure about resolution.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:34:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28609#M20389</guid>
      <dc:creator>lalithagutthi</dc:creator>
      <dc:date>2018-09-13T15:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28610#M20390</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;We Are going to work on this next week, please wait , thanks&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Sep 2018 22:30:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28610#M20390</guid>
      <dc:creator>Nik</dc:creator>
      <dc:date>2018-09-16T22:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28611#M20391</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The number of files written correspond to the number of partitions in the Spark dataframe. To reduce the number to 1 file, use coalesce():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;sqlDF.coalesce(1).write.csv(&amp;lt;file-path&amp;gt;)...&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Sep 2018 23:06:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28611#M20391</guid>
      <dc:creator>User16829051266</dc:creator>
      <dc:date>2018-09-16T23:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28612#M20392</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;I&gt;I do not want the folder. for example, if I were given test.csv, I am expecting CSV file. But, it's showing test.csv folder which contains multiple supporting files. moreover, the data file is coming with a unique name, which difficult to my call in ADF for identifiying name.&lt;/I&gt;&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 00:08:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28612#M20392</guid>
      <dc:creator>lalithagutthi</dc:creator>
      <dc:date>2018-09-17T00:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28613#M20393</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hey Nik /Maggi&lt;/P&gt;
&lt;P&gt;here are my observations &lt;/P&gt;
&lt;P&gt;1. you cannot pass file name in databricks api to other storage service &lt;/P&gt;
&lt;P&gt;2. datalake /blob decides file names &lt;/P&gt;
&lt;P&gt;3. you can rename files after saving them &lt;/P&gt;
&lt;P&gt;Here is solution for you &lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;###### Write your data frame to a single file with default name to a temp location "Part000-XXXXX"
TempFilePath = "wasbs://&amp;lt;DirectoryName&amp;gt;@&amp;lt;Subscription&amp;gt;.blob.core.windows.net/test"
Matrixdatadf.coalesce(1).write\
.mode("overwrite")\
.format("com.databricks.spark.csv")\
.option("header", "true")\
.save(TempFilePath)\
####### now read file from temp location write it to new location with new name and delete temp directory 
readPath = "wasbs://&amp;lt;DirectoryName&amp;gt;@&amp;lt;Subscription&amp;gt;.blob.core.windows.net/test"
writePath = "wasbs://&amp;lt;DirectoryName&amp;gt;@&amp;lt;Subscription&amp;gt;.blob.core.windows.net/MYfolder/ResultFiles"
file_list = dbutils.fs.ls(readPath) #### List out all files in temp directory
for i in file_list:
    file_path = i[0]
    file_name = i[1]
file_name
fname = "test.csv"
for i in file_list:
            if i[1].startswith("part-00000"): #### find your temp file name 
                 read_name = i[1]
# #####Move it outside to the new_dir folder and rename
dbutils.fs.mv(readPath+"/"+read_name, writePath+"/"+fname)
# #Remove the empty folder
dbutils.fs.rm(readPath , recurse= True)
&amp;lt;br&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will be happy to help if some other help required &lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Feb 2019 08:51:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28613#M20393</guid>
      <dc:creator>manojlukhi</dc:creator>
      <dc:date>2019-02-09T08:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28614#M20394</link>
      <description>&lt;P&gt;@Maggie Chu​&amp;nbsp; @lalitha gutthi​&amp;nbsp; Do you have any solution for this issue. Am facing same problem, a folder is getting created with read only mode. But not files inside it. I’m using spark 2.3.1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 17:08:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28614#M20394</guid>
      <dc:creator>Iyyappan</dc:creator>
      <dc:date>2019-05-16T17:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28615#M20395</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I got the answer,- Both input file directory &amp;amp; output file directory should not be same&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 03:02:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28615#M20395</guid>
      <dc:creator>Iyyappan</dc:creator>
      <dc:date>2019-05-17T03:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: write from a Dataframe to a CSV file,  CSV file is blank</title>
      <link>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28616#M20396</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Create temp folder inside output folder. Copy file part-00000* with the file name to output folder. Delete the temp folder. Python code snippet to do the same. &lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;fpath=output+'/'+'temp'
def file_exists(path):
  try:
    dbutils.fs.ls(path)
    return True
  except Exception as e:
    if 'java.io.FileNotFoundException' in str(e):
      return False
    else:
      raise
if file_exists(fpath):
  dbutils.fs.rm(fpath)
  spark.sql(query).coalesce(1).write.csv(fpath)
else:
  spark.sql(query).coalesce(1).write.csv(fpath)
fname=([x.name for x in dbutils.fs.ls(fpath) if x.name.startswith('part-00000')])
dbutils.fs.cp(fpath+"/"+fname[0], output+"/"+"somefile.csv")
dbutils.fs.rm(fpath, True) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;----&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:15:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/write-from-a-dataframe-to-a-csv-file-csv-file-is-blank/m-p/28616#M20396</guid>
      <dc:creator>nl09</dc:creator>
      <dc:date>2020-06-25T16:15:52Z</dc:date>
    </item>
  </channel>
</rss>

