Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally remove the first two characters from a column

I have the below data of some phone records, and I want to remove the first two values from each record as they are a country code. What is the way by which I can do this using Scala, Spark, or Hive?

phone
|917799423934|
|019331224595|
|  8981251522|
|917271767899|

I'd like the result to be:

phone
|7799423934|
|9331224595|
|8981251522|
|7271767899|

How can we remove the prefix 91,01 from each record or each row of this column?

like image 773
Ayush Avatar asked Oct 23 '25 14:10

Ayush


1 Answers

Phone size can be different, such construction can be used (Scala):

df.withColumn("phone", expr("substring(phone,3,length(phone)-2)"))
like image 113
pasha701 Avatar answered Oct 26 '25 09:10

pasha701



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!