withColumn takes a column as the second argument, not string. If you want formatting before show() you can use the round() function. -- Raghavendra
On Mon, May 23, 2022 at 11:35 AM wilson <wil...@4shield.net> wrote: > hello > > how to add a column for percent for the current row of counted data? > > scala> > df2.groupBy("_c1").count.withColumn("percent",f"${col(count)/df2.count}%.2f").show > > <console>:30: error: type mismatch; > > > This doesn't work. > > so please help. thanks. > > > >