cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Am trying to use SQL, but createOrReplaceTempView("myDataView")​ fails

MikeBrewer
New Contributor II

Am trying to use SQL, but createOrReplaceTempView("myDataView") fails.

I can create and display a DataFrame fine...

import pandas as pd
df = pd.DataFrame(['$3,000,000.00','$3,000.00', '$200.5', '$5.5'], columns = ['Amount'])
df

I add another cell, but it fails...

df.createOrReplaceTempView("myDataView")

I get this error..

'DataFrame' object has no attribute 'createOrReplaceTempView'

I see this example out there on the net allot, but don't understand why it fails for me. I am using

Community edition. 6.5 (includes Apache Spark 2.4.5, Scala 2.11)

3 REPLIES 3

-werners-
Esteemed Contributor III

I never worked with pandas on spark, but a pandas dataframe is not the same as a spark dataframe.

You need to convert it to a spark dataframe first with Koalas f.e.

https://koalas.readthedocs.io/en/latest/user_guide/pandas_pyspark.html#pyspark

acorson
New Contributor II

You need to convert the pandas DF to an spark DF. Enabling Apache Arrow will make this process faster.

From https://docs.databricks.com/spark/latest/spark-sql/spark-pandas.html:

import numpy as np import pandas as pd

Enable Arrow-based columnar data transfers

park.conf.set("spark.sql.execution.arrow.enabled", "true")

Generate a pandas DataFrame

df = pd.DataFrame(np.random.rand(100, 3))

Create a Spark DataFrame from a pandas DataFrame using Arrow

f = spark.createDataFrame(pdf)

Convert the Spark DataFrame back to a pandas DataFrame using Arrow

esult_pdf = df.select("*").toPandas()

sachinthana
New Contributor II

This is worked for me. Thank you @acorson​ 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group