Search code examples
pythondataframepysparkdatabricks

AttributeError: 'DataFrame' object has no attribute 'write'...Trying to upload a dataframe to a table in Databricks


I have created a dataframe in databricks as a combination of multiple dataframes. I am now trying to upload that df to a table in my database and I have used this code many times before with no problem, but now it is not working. My code is

df.write.saveAsTable("dashboardco.AccountList")

getting the error: AttributeError: 'DataFrame' object has no attribute 'write'

Thanks for any help!


Solution

  • Most probably your DataFrame is the Pandas DataFrame object, not Spark DataFrame object.

    try:

    spark.createDataFrame(df).write.saveAsTable("dashboardco.AccountList")