c++ select函数_PySpark 操作函数一览
生活随笔
收集整理的這篇文章主要介紹了
c++ select函数_PySpark 操作函数一览
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
PySpark 操作函數一覽
Created: Sep 14, 2020 10:28 AM Tags: Big Data, PySpark, Python, Spark
Pyspark.sql.functions
from pyspark.sql import functions as F函數使用說明
基本數學函數類
- abs
- sin、cos、tan、asin、acos 、atan、sinh、cosh、tanh
- ceil、round、floor
- exp、log、log2、pow、sqrt、cbrt
- factorial
特定類型
日期
- current_date、current_timestamp、add_months、unix_timestamp
- add_months、date_add、date_format、date_sub、date_trunc、date_diff
- dayofmonth、dayofweek、dayofyear、weekofyear
- hour、last_day、minute、month、months_between、next_day、year
字符
- ascii、substring、substring_index
- base64、unbase64
- decode、encode
- expr、conv
- format_string
- length
- lower、upper
- reverse
- size
Binary
- bin、bitwiseNOT、
- hash、md5、sha1、sha2
- hex、unhex
角度
- toDegrees、toRadians、radians
數字
- format_number
判斷
- isnan、isnull
統計計算
- avg、corr、count、countDistinct、cume_dist
- greatest、kurtosis、variance
- max、min、mean、rand、randn、rank
- skewness、sum、sumDistinct
數組處理
- flatten、slice、element_at、array_contains、array_distinct、array_except、array_intersect、array_join、array_max、array_min、array_position、array_remove、array_repeat、array_sort、array_union、arrays_overlap、arrays_zip
數組函數說明
df = spark.createDataFrame([(([1, 2, 3], [2, 3, 4]))], ['vals1', 'vals2']) df.show() df_new = df.select(F.arrays_zip(df.vals1, df.vals2).alias('zipped')) df_new.show() row = df_new.collect()[0] row['zipped'][0]['vals1'] == row['zipped'][0][0] == 1""" +---------+---------+ | vals1| vals2| +---------+---------+ |[1, 2, 3]|[2, 3, 4]| +---------+---------++--------------------+ | zipped| +--------------------+ |[[1, 2], [2, 3], ...| +--------------------+True """列處理
- coalesce
- array
- concat、concat_ws
- col、column、lit
- explode、explode_outer、posexplode、posexplode_outer
- from_csv、from_json、get_json_object
- create_map、map_from_arrays、map_from_entries、map_concat、map_keys、map_values、map_entries
- regexp_extract、regexp_replace
- udf
Pyspark.sql.types
Base 類型
- DataType
基本類型
- NullType
- StringType
- BinaryType
- BooleanType
- DateType
- TimestampType
- DecimalType
- DoubleType
- FloatType
- ByteType
- IntegerType
- LongType
- ShortType
疊加類型
ArrayType
df = spark.createDataFrame([([1,2,3])], schema=ArrayType(IntegerType()) ) df.show() # +---------+ # | value| # +---------+ # |[1, 2, 3]| # +---------+df.collect()[0].value[0] # 1 # 默認的 column name 為 valueMapType
df = spark.createDataFrame([({'a': 1, 'b': 2})], schema=MapType(StringType(), IntegerType()) ) df.show() # +----------------+ # | value| # +----------------+ # |[a -> 1, b -> 2]| # +----------------+df.collect()[0]['value']['a'] # 1StructField
# 需要搭配 StructType 使用 StructField('column_name', DataType, is_nullable)StructType
df = spark.createDataFrame([(1,)], schema=StructType([StructField('col', IntegerType())])) df.show() """ +---+ |col| +---+ | 1| +---+ """# 復雜一些的情況 df = spark.createDataFrame([({'a': [2,3,4]},)], schema=StructType([StructField('col', MapType(StringType(), ArrayType(IntegerType())))])) df.show() """ +----------------+ | col| +----------------+ |[a -> [2, 3, 4]]| +----------------+ """df.collect()[0]['col']['a'][0] # 2總結
以上是生活随笔為你收集整理的c++ select函数_PySpark 操作函数一览的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蜗居时代剧情介绍
- 下一篇: word2003如何设置护眼模式_ERP