Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

making spark session

from pyspark.sql import SparkSession

spark = SparkSession 
    .builder 
    .appName("Python Spark SQL basic example") 
    .config("spark.some.config.option", "some-value") 
    .getOrCreate()
Comment

spark session creation examples

# Need to import to use date time
from datetime import datetime, date
 
# need to import for working with pandas
import pandas as pd
 
# need to import to use pyspark
from pyspark.sql import Row
 
# need to import for session creation
from pyspark.sql import SparkSession
 
# creating the session
spark = SparkSession.builder.getOrCreate()
 
# schema creation by passing list
df = spark.createDataFrame([
    Row(a=1, b=4., c='GFG1', d=date(2000, 8, 1),
        e=datetime(2000, 8, 1, 12, 0)),
   
    Row(a=2, b=8., c='GFG2', d=date(2000, 6, 2),
        e=datetime(2000, 6, 2, 12, 0)),
   
    Row(a=4, b=5., c='GFG3', d=date(2000, 5, 3),
        e=datetime(2000, 5, 3, 12, 0))
])
 
# show table
df.show()
 
# show schema
df.printSchema()
Comment

PREVIOUS NEXT
Code Example
Python :: panda dataframe to list 
Python :: tkinter python may not be configured for Tk 
Python :: subplot matplotlib set limits 
Python :: get current month python 
Python :: droaw heat map in python for null values 
Python :: edge driver selenium python 
Python :: pip neat 
Python :: how to make a python program to count from 1 to 100 
Python :: cv2 hconcat 
Python :: how to plot a graph using matplotlib 
Python :: replace cell pandas 
Python :: remove negative numbers from list python 
Python :: install os python 
Python :: how to edit a specific line in text file in python 
Python :: how to pass header in requests 
Python :: python3 as default python path macos 
Python :: how to spread an array in python 
Python :: how to remove first row of numpy array 
Python :: python join generators 
Python :: text to ascii art python 
Python :: sns seaborn set theme 
Python :: how to make text bold in tkinter 
Python :: install auto-py-to-exe 
Python :: how to see the functions of a library in python 
Python :: python printing date 
Python :: turn off pycache python 
Python :: how to check suffix in python 
Python :: how to make jupyterlab see other directory 
Python :: extract numbers from sklearn classification_report 
Python :: get all columns names starting with pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =