Created
February 4, 2018 23:19
-
-
Save dgadiraju/9c3a71eebbeee3e6f381795f8684495a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#String Manipulation | |
orders = sc.textFile("/public/retail_db/orders") | |
s = orders.first() | |
#first character from a string | |
s[0] | |
#first 10 characters from a string | |
s[:10] | |
#get length of string | |
len(s) | |
#One way to get the date, but it will not work if the order id before first | |
#comma is more than one character or digit | |
s[2:12] | |
#split and extract date | |
s.split(",") | |
type(s.split(",")) | |
#Get Date | |
s.split(",")[1] | |
#Get customer id | |
s.split(",")[2] | |
#type casting to integer | |
int(s.split(",")[0]) | |
#type casting integer to string | |
print("printing " + str(1)) | |
int(s.split(",")[1].split(" ")[0].replace("-", "")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment