Try this: import pyspark.sql.functions as f df = spark.createDataFrame([ ('Calgary', 2) ], ['CityName', 'Length']) df = ( df .withColumn('test', f.expr('substring(CityName, 2, Length)')) ) 本站已为你智能检索到如下内容,以供参考: 🐻 相关问答 5 个 1、Python Dataframe Get ...
In this section, You can find out how to replace the substring usingDataFrame.apply() andlambdafunction. Theapply() functionin Pandas enables you to apply a function along one of the axes of the DataFrame, be it rows or columns. The below example replaces multiple substrings. # Replace S...
df:The PySpark DataFrame. b = a.withColumn("Sub_Name",a.Name.substr(1,3)) Screenshot: The withColumn function is used in PySpark to introduce New Columns in Spark DataFrame. a.Name is the name of column name used to work with the DataFrame String whose value needs to be fetched. Work...