import
pyspark
from
pyspark.sql
import
SparkSession
from
pyspark.sql.types
import
StringType, DoubleType,
IntegerType, StructType, StructField, FloatType
spark
=
SparkSession.builder.appName(
'sparkdf'
).getOrCreate()
data
=
[(
1
,
"sravan"
,
9.8
,
4500.00
), (
2
,
"ojsawi"
,
9.2
,
6789.00
),
(
3
,
"bobby"
,
8.9
,
988.000
)]
columns
=
StructType([
StructField(
"ID"
, IntegerType(),
True
),
StructField(
"NAME"
, StringType(),
True
),
StructField(
"GPA"
, FloatType(),
True
),
StructField(
"FEE"
, DoubleType(),
True
),
])
dataframe
=
spark.createDataFrame(data, columns)
print
(dataframe[[f.name
for
f
in
dataframe.schema.fields
if
isinstance
(
f.dataType, IntegerType)]].collect())
print
(dataframe[[f.name
for
f
in
dataframe.schema.fields
if
isinstance
(
f.dataType, StringType)]].collect())
print
(dataframe[[f.name
for
f
in
dataframe.schema.fields
if
isinstance
(
f.dataType, FloatType)]].collect())
print
(dataframe[[f.name
for
f
in
dataframe.schema.fields
if
isinstance
(
f.dataType, DoubleType)]].collect())