I am trying to remove the first character from some of the columns in the dataframe df_rotina_pro
. But I am getting the following error:
Column is not iterable.
Code:
transformed_df = (
df_rotina_pro.withColumn(
"cprodlim", F.substring(df_rotina_pro["cprodlim"], 2, F.length(["cprodlim"]))
)
.withColumn(
"col1", F.substring(df_rotina_pro["col1"], 2, F.length(df_rotina_pro["col1"]))
)
.withColumn(
"col2", F.substring(df_rotina_pro["col2"], 2, F.length(df_rotina_pro["col2"]))
)
.withColumn(
"col3", F.substring(df_rotina_pro["col3"], 2, F.length(df_rotina_pro["col3"]))
)
.withColumn(
"col4", F.substring(df_rotina_pro["col4"], 2, F.length(df_rotina_pro["col4"]))
)
.withColumn(
"col5", F.substring(df_rotina_pro["col5"], 2, F.length(df_rotina_pro["col5"]))
)
.withColumn(
"col6", F.substring(df_rotina_pro["col6"], 2, F.length(df_rotina_pro["col6"]))
)
.withColumn(
"col7", F.substring(df_rotina_pro["col7"], 2, F.length(df_rotina_pro["col7"]))
)
.withColumn(
"col8", F.substring(df_rotina_pro["col8"], 2, F.length(df_rotina_pro["col8"]))
)
.withColumn(
"col9", F.substring(df_rotina_pro["col9"], 2, F.length(df_rotina_pro["col9"]))
)
)
Please, help me to solve this because I have tried a lot of other ways to do it and none of them worked.
New contributor
Lívia Vialta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.