Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyspark access column of dataframe with a dot '.'

A pyspark dataframe containing dot (e.g. "id.orig_h") will not allow to groupby upon unless first renamed by withColumnRenamed. Is there a workaround? "`a.b`" doesn't seem to solve it.

like image 464
Hanan Shteingart Avatar asked Dec 14 '22 06:12

Hanan Shteingart


1 Answers

In my pyspark shell, the following snippets are working:

from pyspark.sql.functions import *
myCol = col("`id.orig_h`")    
result = df.groupBy(myCol).agg(...)

and

myCol = df["`id.orig_h`"]   
result = df.groupBy(myCol).agg(...)

I hope it helps.

like image 107
Daniel de Paula Avatar answered Jan 03 '23 04:01

Daniel de Paula