Skip to content

Instantly share code, notes, and snippets.

PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked
1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/5 21171 7.25 S
2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38.0 1 0 PC 17599 71.2833 C85 C
3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.925 S
4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1 C123 S
5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.05 S
summary Survived SibSp Pclass Parch Fare
count 891.0 891.0 891.0 891.0 891.0
mean 0.384 0.523 2.309 0.382 32.204
stddev 0.487 1.103 0.836 0.806 49.693
min 0.0 0.0 1.0 0.0 0.0
max 1.0 8.0 3.0 6.0 512.329
# Implementation with PySpark
from pyspark.sql import SparkSession
from pyspark.sql import Window
from pyspark.sql import functions as f
# Define Spark settings
builder = SparkSession.builder.appName("Discount_Cashflows")
spark = builder.getOrCreate()
# Read in the cash flows data and rate data as csv
Product Year Cash flows Currency
Flood insurance 0 24000 USD
Flood insurance 1 -2000 USD
Flood insurance 2 -2000 USD
Flood insurance 3 -2000 USD
Flood insurance 4 -2000 USD
Flood insurance 5 -2000 USD
Flood insurance 6 -2000 USD
Flood insurance 7 -2000 USD
Flood insurance 8 -2000 USD
Year Interest rate Currency
1 0.03 EUR
2 0.031 EUR
3 0.032 EUR
4 0.033 EUR
1 0.020 GBP
2 0.021 GBP
3 0.022 GBP
4 0.023 GBP
Currency Country
GBP UK
EUR Italy
EUR France
EUR Belgium
EUR Germany
Client Insurance product Country Duration Price Payment year 1 Payment year 2 Payment year 3 Payment year 4
A Small car UK 1 200 0 50 30 0
B Small car Italy 1 100 0 0 0 80
C Small car UK 1 200 0 35 40 20
D Small car UK 1 220 0 40 60 0
E Small car France 1 200 0 20 30 50
F Businss car Belgium 1 450 0 100 100 100
G Businss car Germany 1 470 0 120 80 0
H Businss car UK 1 400 60 70 100 0
I Businss car UK 1 400 50 70 20 80
Client Insurance product Country Duration Price Payment year 1 Payment year 2 Payment year 3 Payment year 4
A Small car UK 1 200 0 50 30 0