0
line = "Hello, world"
sc.parallelize(list(line)).collect()

I obtain the following error

TypeError: parallelize() missing 1 required positional argument: 'c'

I also have an other issue when creating a dataframe from a list of strings with only one column:

from pyspark.sql.types import *
from pyspark.sql import SQLContext
sqlContext = SQLContext(sc)
schema = StructType([StructField("name", StringType(), True)])
df3 = sqlContext.createDataFrame(fuzzymatchIntro, schema)
df3.printSchema()

I obtain the following error:

----> 3 sqlContext = SQLContext(sc)
AttributeError: type object 'SparkContext' has no attribute '_jsc'

Thank you in advance

2
  • how did you create sc? Commented Mar 19, 2018 at 11:31
  • from pyspark.context import SparkContext from pyspark.sql.session import SparkSession sc = SparkContext spark = SparkSession.builder.appName("DFTest").getOrCreate() Commented Mar 19, 2018 at 12:25

2 Answers 2

1

Looking at your comment above, you seem to have initialized sparkContext in a wrong way as you have done

from pyspark.context import SparkContext from pyspark.sql.session import SparkSession sc = SparkContext spark = SparkSession.builder.appName("DFTest").getOrCreate()

The correct way would be

from pyspark.sql.session import SparkSession
spark = SparkSession.builder.appName("DFTest").getOrCreate()
sc = spark.sparkContext

And spark object can do the work of sqlContext

Sign up to request clarification or add additional context in comments.

Comments

0

I tried above suggestion in my pyspark in windows using the Jupyter terminal and it has worked. Please find my sample code below which worked for me

import findspark
findspark.init()
import pyspark
from pyspark.sql.session import SparkSession
spark = SparkSession.builder.appName("DFTest").getOrCreate()
sc = spark.sparkContext
words = sc.parallelize(["scala","java","hadoop","spark","akka","spark vs 
hadoop","pyspark","pyspark and spark"])
counts = words.count()
print("Number of elements in RDD -> %i" % (counts))

1 Comment

How is this different from Ramesh Maharjan's answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.