Apache spark “创建新的”;时区“;TimezoneFinder()中的列,其中经度和纬度列作为PySpark中的输入

Apache spark “创建新的”;时区“;TimezoneFinder()中的列,其中经度和纬度列作为PySpark中的输入,apache-spark,pyspark,timezone,user-defined-functions,Apache Spark,Pyspark,Timezone,User Defined Functions,我想创建一个新列,其中包含等效经度和纬度的时区。现有列的经度和纬度是timezonefinder函数的输入,即get_timezone()。我一直在获取TypeError:需要一个整数(获取类型列) 谢谢 from timezonefinder import TimezoneFinder def get_timezone(longitude, latitude): tzf = TimezoneFinder() return tzf.timezone_at(lng=longitu

我想创建一个新列,其中包含等效经度和纬度的时区。现有列的经度和纬度是timezonefinder函数的输入,即get_timezone()。我一直在获取
TypeError:需要一个整数(获取类型列)

谢谢

from timezonefinder import TimezoneFinder

def get_timezone(longitude, latitude):
    tzf = TimezoneFinder()
    return tzf.timezone_at(lng=longitude, lat=latitude)

location_table = location_table.withColumn("timezone", get_timezone(location_table["location_longitude"], location_table["location_latitude"]))
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在里面
8.
9#df=sqlContext.read.parquet(输入)
--->10位置表。带列(“时区”,获取位置表[“位置经度”]。强制转换(IntegerType()),位置表[“位置经度”]。强制转换(IntegerType()))
11#.写.拼花地板(输出)
在get_时区(经度、纬度)
3 def get_时区(经度、纬度):
4 tzf=时区文件夹()
---->5返回tzf.时区(lng=经度,lat=纬度)
6.
7#udf_timezone=F.udf(get_timezone,StringType())
/时区中的databricks/python/lib/python3.7/site-packages/timezonefinder/timezonefinder.py(self、lng、lat)
657:返回:匹配时区多边形的时区名称。如果是海洋时区,则可能为“Etc/GMT+-XX”。
658         """
-->659 lng,lat=校正坐标(lng,lat)
660
661快捷方式\u id\u x,快捷方式\u id\u y=coord2shortcut(lng,lat)
TypeError:需要一个整数(Get type列)

您需要先将函数转换为自定义项:

import pyspark.sql.functions as F
from timezonefinder import TimezoneFinder

@F.udf('string')
def get_timezone(longitude, latitude):
    if longitude is None or latitude is None:
        return None
    tzf = TimezoneFinder()
    return tzf.timezone_at(lng=longitude, lat=latitude)

location_table = location_table.withColumn("timezone", get_timezone(location_table["location_longitude"], location_table["location_latitude"]))
import pyspark.sql.functions as F
from timezonefinder import TimezoneFinder

@F.udf('string')
def get_timezone(longitude, latitude):
    if longitude is None or latitude is None:
        return None
    tzf = TimezoneFinder()
    return tzf.timezone_at(lng=longitude, lat=latitude)

location_table = location_table.withColumn("timezone", get_timezone(location_table["location_longitude"], location_table["location_latitude"]))