用法:
groupby(*args, **kwargs)
使用映射器或按一係列列對 DataFrame 進行分組。
groupby 操作涉及拆分對象、應用函數和組合結果的某種組合。這可用於對大量數據進行分組並在這些組上進行計算操作。
- by:映射、函數、標簽或標簽列表
用於確定 groupby 的組。如果 by 是一個函數,它會在對象索引的每個值上調用。如果傳遞了 dict 或 Series,則 Series 或 dict VALUES 將用於確定組(Series 的值首先對齊;參見 .align() 方法)。如果傳遞了一個cupy數組,則使用這些值as-is確定組。一個標簽或標簽列表可以通過 self 中的列傳遞給 group。請注意,元組被解釋為(單個)鍵。
- level:int,級別名稱或此類的序列,默認無
如果軸是 MultiIndex(分層),則按特定級別或多個級別分組。
- as_index:布爾值,默認為真
對於聚合輸出,返回以組標簽為索引的對象。僅與 DataFrame 輸入相關。 as_index=False 實際上是 “SQL-style” 分組輸出。
- sort:布爾值,默認為 False
按組鍵對結果進行排序。與 Pandas 不同,cudf 默認為
False
以獲得更好的性能。請注意,這不會影響每組內的觀察順序。 Groupby 保留每個組內的行順序。- dropna:布爾型,可選
如果為 True(默認),則不包括 “null” 組。
- DataFrameGroupBy
返回包含有關組的信息的 groupby 對象。
參數:
返回:
例子:
>>> import cudf >>> import pandas as pd >>> df = cudf.DataFrame({ ... 'Animal': ['Falcon', 'Falcon', 'Parrot', 'Parrot'], ... 'Max Speed': [380., 370., 24., 26.], ... }) >>> df Animal Max Speed 0 Falcon 380.0 1 Falcon 370.0 2 Parrot 24.0 3 Parrot 26.0 >>> df.groupby(['Animal']).mean() Max Speed Animal Falcon 375.0 Parrot 25.0
>>> arrays = [['Falcon', 'Falcon', 'Parrot', 'Parrot'], ... ['Captive', 'Wild', 'Captive', 'Wild']] >>> index = pd.MultiIndex.from_arrays(arrays, names=('Animal', 'Type')) >>> df = cudf.DataFrame({'Max Speed': [390., 350., 30., 20.]}, ... index=index) >>> df Max Speed Animal Type Falcon Captive 390.0 Wild 350.0 Parrot Captive 30.0 Wild 20.0 >>> df.groupby(level=0).mean() Max Speed Animal Falcon 370.0 Parrot 25.0 >>> df.groupby(level="Type").mean() Max Speed Type Wild 185.0 Captive 210.0
相關用法
- Python cuspatial.GeoSeries用法及代碼示例
- Python cuspatial.GeoArrowBuffers用法及代碼示例
- Python cuspatial.CubicSpline用法及代碼示例
- Python cuspatial.quadtree_on_points用法及代碼示例
- Python cuspatial.trajectory_bounding_boxes用法及代碼示例
- Python cuspatial.derive_trajectories用法及代碼示例
- Python cuspatial.directed_hausdorff_distance用法及代碼示例
- Python cuspatial.trajectory_distances_and_speeds用法及代碼示例
- Python cuspatial.point_in_polygon用法及代碼示例
- Python cusignal.windows.windows.hann用法及代碼示例
- Python cusignal.windows.windows.general_gaussian用法及代碼示例
- Python cusignal.waveforms.waveforms.chirp用法及代碼示例
- Python cusignal.windows.windows.gaussian用法及代碼示例
- Python cusignal.windows.windows.hamming用法及代碼示例
- Python cusignal.windows.windows.get_window用法及代碼示例
- Python cusignal.waveforms.waveforms.gausspulse用法及代碼示例
- Python cusignal.peak_finding.peak_finding.argrelmin用法及代碼示例
- Python cusignal.windows.windows.bartlett用法及代碼示例
- Python cusignal.spectral_analysis.spectral.welch用法及代碼示例
- Python cusignal.windows.windows.chebwin用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cuspatial.GeoDataFrame.groupby。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。