TypeError: function() argument 'code' must be code, not str in Azure Synapse Notebook

Dhilip Subramanian 41 Reputation points
2022-06-26T02:53:48.077+00:00

I am having below data frame and wanted to save the data frame as a CSV file in the Azure Data lake. My data frame is called 'df'. I am using Azure Synpase Notebook

215039-image.png

df.to_csv('abfss://email address removed for privacy reasons/Jobs_newdata/data.csv', sep=',', encoding='utf-8', index=False)  

Getting below error message when I tried to run the above code

214998-image.png

Can anyone advise what is the issue here?

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,004 questions
0 comments No comments
{count} votes

Accepted answer
  1. HimanshuSinha-msft 19,476 Reputation points Microsoft Employee
    2022-06-27T21:48:32.763+00:00

    Hello @Dhilip Subramanian ,
    Thanks for the question and using MS Q&A platform.

    As we understand the ask here is to get write the dataframe to a storage account in the CSV format, please do let us know if its not accurate.
    You are calling the storage account as
    abfss://email address removed for privacy reasons/Jobs_newdata/data.csv
    You said call this
    abfss://yourcontainername@YourStorageAccountName.dfs.core.windows.net/email address removed for privacy reasons/Jobs_newdata/data.csv

    The below piece of code just works fine .

    filePath = "abfss://yourcontainername@analyticssynapsews.dfs.core.windows.net/email address removed for privacy reasons/Jobs_newdata/data.csv"

    d = {'col1': [1, 2], 'col2': [3, 4]}
    pd = pandas.DataFrame(d)
    df = spark.createDataFrame(pd)
    df.write.format("csv").mode("overwrite").save(filePath)

    215436-image.png

    Please do let me if you have any queries.
    Thanks
    Himanshu


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
      • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

1 additional answer

Sort by: Most helpful
  1. Abdullah Alattar 92 Reputation points
    2022-08-26T21:07:23.237+00:00

    Dear @HimanshuSinha-msft ,

    Is there way to save to csv without using spark ?, because it divides the data.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.