<?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 OSError: Invalid argument when attempting to save a pandas dataframe to csv in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/oserror-invalid-argument-when-attempting-to-save-a-pandas/m-p/6744#M2766</link>
    <description>&lt;P&gt;I am attempting to save a pandas DataFrame to as&amp;nbsp;csv to a directory I created in Databricks workspace or in the `cwd`. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import pandas as pd
&amp;nbsp;
import os
&amp;nbsp;
df.to_csv("data.csv", index=False)
&amp;nbsp;
df.to_csv(str(os.getcwd()) + "/data.csv", index=False)
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;OSError: [Errno 22] Invalid argument
&amp;nbsp;
---------------------------------------------------------------------------
&amp;nbsp;
OSError                                   Traceback (most recent call last)
&amp;nbsp;
File :2
&amp;nbsp;
      1 # Save CSV to Databricks filesystem
&amp;nbsp;
----&amp;gt; 2 df.to_csv("pmf_remax.csv", index=False)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am also saving a file using `&lt;A href="https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_file.html" alt="https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_file.html" target="_blank"&gt;_file` &lt;/A&gt;` method and while it doesn't throw an error, i don't see the file in the `cwd`. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;***.to_file(str(os.getcwd()) + '/us_df.geojson', driver='GeoJSON')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when i save a file, where does it save it? I tried to run the command `find . -name example.txt` from the root directory in the web terminal and didn't find it. &lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2023 17:37:53 GMT</pubDate>
    <dc:creator>kll</dc:creator>
    <dc:date>2023-03-30T17:37:53Z</dc:date>
    <item>
      <title>OSError: Invalid argument when attempting to save a pandas dataframe to csv</title>
      <link>https://community.databricks.com/t5/data-engineering/oserror-invalid-argument-when-attempting-to-save-a-pandas/m-p/6744#M2766</link>
      <description>&lt;P&gt;I am attempting to save a pandas DataFrame to as&amp;nbsp;csv to a directory I created in Databricks workspace or in the `cwd`. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import pandas as pd
&amp;nbsp;
import os
&amp;nbsp;
df.to_csv("data.csv", index=False)
&amp;nbsp;
df.to_csv(str(os.getcwd()) + "/data.csv", index=False)
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;OSError: [Errno 22] Invalid argument
&amp;nbsp;
---------------------------------------------------------------------------
&amp;nbsp;
OSError                                   Traceback (most recent call last)
&amp;nbsp;
File :2
&amp;nbsp;
      1 # Save CSV to Databricks filesystem
&amp;nbsp;
----&amp;gt; 2 df.to_csv("pmf_remax.csv", index=False)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am also saving a file using `&lt;A href="https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_file.html" alt="https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_file.html" target="_blank"&gt;_file` &lt;/A&gt;` method and while it doesn't throw an error, i don't see the file in the `cwd`. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;***.to_file(str(os.getcwd()) + '/us_df.geojson', driver='GeoJSON')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when i save a file, where does it save it? I tried to run the command `find . -name example.txt` from the root directory in the web terminal and didn't find it. &lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 17:37:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/oserror-invalid-argument-when-attempting-to-save-a-pandas/m-p/6744#M2766</guid>
      <dc:creator>kll</dc:creator>
      <dc:date>2023-03-30T17:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Invalid argument when attempting to save a pandas dataframe to csv</title>
      <link>https://community.databricks.com/t5/data-engineering/oserror-invalid-argument-when-attempting-to-save-a-pandas/m-p/6745#M2767</link>
      <description>&lt;P&gt;Hi @Keval Shah​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can save your dataframe to csv in dbfs storage.&lt;/P&gt;&lt;P&gt;Please refer below code that might help you-&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df = pd.read_csv(StringIO(data), sep=',')
#print(df)
df.to_csv('/dbfs/FileStore/ajay/file1.txt')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 11:27:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/oserror-invalid-argument-when-attempting-to-save-a-pandas/m-p/6745#M2767</guid>
      <dc:creator>Ajay-Pandey</dc:creator>
      <dc:date>2023-03-31T11:27:40Z</dc:date>
    </item>
  </channel>
</rss>

