Я создал таблицу myTable
из файла .csv, как вы в следующем
schema= StructType([
StructField("identifier", StringType(), True),
StructField("identifier_type", StringType(), True),
StructField("timestamp", TimestampType(), True),
StructField("device_lat", FloatType(), True),
StructField("device_lon", FloatType(), True)])
myTable = spark.read.format("csv").schema(schema).option("timestampFormat","yyyy-mm-dd hh:mm:ss").load('myFile.csv')
myTable = myTable[myTable['device_lat']>0]
sqlContext.registerDataFrameAsTable(myTable, "myTable")
+--------------------+---------------+-------------------+----------+----------+
| identifier|identifier_type| timestamp| lat| lon|
+--------------------+---------------+-------------------+----------+----------+
|68d62a1b-b928-422...| gggx|2020-01-19 03:03:00| 44.80817| -73.52296|
|1675a629-a010-44b...| gggx|2020-01-18 21:15:42| 42.103893|-76.799164|
|0fe7a0b7-028e-459...| gggx|2020-01-18 23:39:54| 43.18203| -77.67202|
|4caa7437-6a59-4aa...| gggx|2020-01-18 18:27:14| 43.092876| -79.05402|
+--------------------+---------------+-------------------+----------+----------+
Я хотел бы выполнить запрос, который вычисляет среднечасовое значение для каждого дня и для каждого пользователя.
Я хотел бы иметь что-то вроде следующего, где значения не являются реальными, а столбец hour
это просто для того, чтобы показать, что каждый пользователь должен 24
строк в день
myTable
identifier identifier_type day hour mean_lat mean_lon
A gggx 2020-01-18 0 44.80817 -73.52296
A gggx 2020-01-18 1 44.80817 -73.52296
. . . . . .
. . . . . .
. . . . . .
A gggx 2020-01-18 22 44.80817 -73.52296
A gggx 2020-01-18 23 44.80817 -73.52296
A gggx 2020-01-19 0 44.80817 -73.52296
A gggx 2020-01-19 1 44.80817 -73.52296