Search
 
SCRIPT & CODE EXAMPLE
 

SQL

pyspark sql row get value

# library import
import pyspark
from pyspark.sql import SparkSession
from pyspark.sql import Row

# Session Creation
random_value_session = SparkSession.builder.appName(
	'Random_Value_Session'
).getOrCreate()

# Data filled in our DataFrame
# 5 rows below
rows = [['All England Open', 'March', 'Super 1000'],
		['Malaysia Open', 'January', 'Super 750'],
		['Korea Open', 'April', 'Super 500'],
		['Hylo Open', 'November', 'Super 100'],
		['Spain Masters', 'March', 'Super 300']]

# Columns of our DataFrame
columns = ['Tournament', 'Month', 'Level']

#DataFrame is created
dataframe = random_value_session.createDataFrame(rows,
												columns)

# Showing the DataFrame
dataframe.show()

# getting list of rows using collect()
row_list = dataframe.collect()

# Printing the first Row object
# from which data is extracted
print(row_list[0])

# Using __getitem__() magic method
# To get value corresponding to a particular
# column
print(row_list[0].__getitem__('Level'))
print(row_list[0].__getitem__('Tournament'))
print(row_list[0].__getitem__('Level'))
print(row_list[0].__getitem__('Month'))
Comment

PREVIOUS NEXT
Code Example
Sql :: postgresql remove new line from string 
Sql :: primary key multiple colums 
Sql :: postgres duplicate key value violates unique constraint already exists 
Sql :: activate event scheduler mariadb 
Sql :: activate log mysql 
Sql :: soql last week 
Sql :: mysqli connect 
Sql :: sql reverse order of results 
Sql :: date in oracle 
Sql :: declare varchar sql server 
Sql :: r rmysql connect local database Plugin caching_sha2_password could not be loaded 
Sql :: osx stop mysql service 
Sql :: mysql date equals to current_date plus days 
Sql :: flask marshmallow sqlalchemy 
Sql :: increment integer in table sql 
Sql :: postgres 11 add primary key 
Sql :: mysql repeated values 
Sql :: oracle alter table add column default value 
Sql :: insert into values select 
Sql :: sql integer to serial 
Sql :: sql delete column 
Sql :: mysql case 
Sql :: lower case in sql 
Sql :: mysql_num_fields in mysqli 
Sql :: How to backup databases using psql 
Sql :: sql power function 
Sql :: how to declare a variable in sql 
Sql :: for select oracle 
Sql :: date get month number sql 
Sql :: sql select all records from all tables where not empty 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =