本文簡要介紹
pyspark.pandas.concat
的用法。用法:
pyspark.pandas.concat(objs: List[Union[pyspark.pandas.frame.DataFrame, pyspark.pandas.series.Series]], axis: Union[int, str] = 0, join: str = 'outer', ignore_index: bool = False, sort: bool = False) → Union[pyspark.pandas.series.Series, pyspark.pandas.frame.DataFrame]
沿特定軸連接 pandas-on-Spark 對象,並沿其他軸連接可選的設置邏輯。
- objs:係列或DataFrame 的序列
任何 None 對象都將被靜默刪除,除非它們都是 None 在這種情況下將引發 ValueError
- axis:{0/'index', 1/'columns'},默認 0
要連接的軸。
- join:{‘inner’, ‘outer’},默認 ‘outer’
如何處理其他軸(或軸)上的索引。
- ignore_index:布爾值,默認為 False
如果為 True,則不要沿連接軸使用索引值。結果軸將標記為 0, ..., n - 1。如果您要連接對象,而連接軸沒有有意義的索引信息,這將非常有用。請注意,連接中仍然尊重其他軸上的索引值。
- sort:布爾值,默認為 False
如果尚未對齊,則對非串聯軸進行排序。
- 對象,對象類型
當沿索引 (axis=0) 連接所有
Series
時,將返回Series
。當objs
至少包含一個DataFrame
時,返回一個DataFrame
。沿列連接時 (axis=1),返回DataFrame
。
參數:
返回:
例子:
>>> from pyspark.pandas.config import set_option, reset_option >>> set_option("compute.ops_on_diff_frames", True)
合並兩個
Series
。>>> s1 = ps.Series(['a', 'b']) >>> s2 = ps.Series(['c', 'd']) >>> ps.concat([s1, s2]) 0 a 1 b 0 c 1 d dtype: object
通過將
ignore_index
選項設置為True
來清除現有索引並在結果中將其重置。>>> ps.concat([s1, s2], ignore_index=True) 0 a 1 b 2 c 3 d dtype: object
將兩個具有相同列的
DataFrame
對象組合在一起。>>> df1 = ps.DataFrame([['a', 1], ['b', 2]], ... columns=['letter', 'number']) >>> df1 letter number 0 a 1 1 b 2 >>> df2 = ps.DataFrame([['c', 3], ['d', 4]], ... columns=['letter', 'number']) >>> df2 letter number 0 c 3 1 d 4
>>> ps.concat([df1, df2]) letter number 0 a 1 1 b 2 0 c 3 1 d 4
將
DataFrame
和Series
對象與不同的列組合在一起。>>> ps.concat([df2, s1]) letter number 0 0 c 3.0 None 1 d 4.0 None 0 None NaN a 1 None NaN b
將
DataFrame
對象與重疊列組合並返回所有內容。交叉點外的列將填充None
值。>>> df3 = ps.DataFrame([['c', 3, 'cat'], ['d', 4, 'dog']], ... columns=['letter', 'number', 'animal']) >>> df3 letter number animal 0 c 3 cat 1 d 4 dog
>>> ps.concat([df1, df3]) letter number animal 0 a 1 None 1 b 2 None 0 c 3 cat 1 d 4 dog
對列進行排序。
>>> ps.concat([df1, df3], sort=True) animal letter number 0 None a 1 1 None b 2 0 cat c 3 1 dog d 4
將
DataFrame
對象與重疊列組合在一起,並僅返回那些通過將inner
傳遞給join
關鍵字參數來共享的對象。>>> ps.concat([df1, df3], join="inner") letter number 0 a 1 1 b 2 0 c 3 1 d 4
>>> df4 = ps.DataFrame([['bird', 'polly'], ['monkey', 'george']], ... columns=['animal', 'name'])
與柱軸結合。
>>> ps.concat([df1, df4], axis=1) letter number animal name 0 a 1 bird polly 1 b 2 monkey george
>>> reset_option("compute.ops_on_diff_frames")
相關用法
- Python pyspark concat_ws用法及代碼示例
- Python pyspark concat用法及代碼示例
- Python pyspark conv用法及代碼示例
- Python pyspark covar_samp用法及代碼示例
- Python pyspark corr用法及代碼示例
- Python pyspark covar_pop用法及代碼示例
- Python pyspark coalesce用法及代碼示例
- Python pyspark collect_list用法及代碼示例
- Python pyspark count_distinct用法及代碼示例
- Python pyspark collect_set用法及代碼示例
- Python pyspark create_map用法及代碼示例
- Python pyspark crc32用法及代碼示例
- Python pyspark date_add用法及代碼示例
- Python pyspark DataFrame.to_latex用法及代碼示例
- Python pyspark DataStreamReader.schema用法及代碼示例
- Python pyspark MultiIndex.size用法及代碼示例
- Python pyspark arrays_overlap用法及代碼示例
- Python pyspark Series.asof用法及代碼示例
- Python pyspark DataFrame.align用法及代碼示例
- Python pyspark Index.is_monotonic_decreasing用法及代碼示例
- Python pyspark IsotonicRegression用法及代碼示例
- Python pyspark DataFrame.plot.bar用法及代碼示例
- Python pyspark DataFrame.to_delta用法及代碼示例
- Python pyspark element_at用法及代碼示例
- Python pyspark explode用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.concat。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。