用法:
class cudf.DataFrame(data=None, index=None, columns=None, dtype=None, nan_as_null=True)
一个 GPU DataFrame 对象。
- data:array-like、Iterable、dict 或 DataFrame。
Dict 可以包含 Series、数组、常量或 list-like 对象。
- index:索引或array-like
用于结果帧的索引。如果输入数据没有索引信息部分并且没有提供索引,则默认为 RangeIndex。
- columns:索引或array-like
用于生成的框架的列标签。如果没有提供列标签,将默认为 RangeIndex (0, 1, 2, ..., n)。
- dtype:dtype,默认无
要强制的数据类型。只允许使用一个 dtype。如果没有,推断。
- nan_as_null:布尔值,默认为真
如果
None
/True
,将np.nan
值转换为null
值。如果False
,保持np.nan
值不变。
参数:
例子:
使用
__setitem__
构建 DataFrame :>>> import cudf >>> df = cudf.DataFrame() >>> df['key'] = [0, 1, 2, 3, 4] >>> df['val'] = [float(i + 10) for i in range(5)] # insert column >>> df key val 0 0 10.0 1 1 11.0 2 2 12.0 3 3 13.0 4 4 14.0
通过列的 dict 构建 DataFrame:
>>> import numpy as np >>> from datetime import datetime, timedelta >>> t0 = datetime.strptime('2018-10-07 12:00:00', '%Y-%m-%d %H:%M:%S') >>> n = 5 >>> df = cudf.DataFrame({ ... 'id': np.arange(n), ... 'datetimes': np.array( ... [(t0+ timedelta(seconds=x)) for x in range(n)]) ... }) >>> df id datetimes 0 0 2018-10-07 12:00:00 1 1 2018-10-07 12:00:01 2 2 2018-10-07 12:00:02 3 3 2018-10-07 12:00:03 4 4 2018-10-07 12:00:04
通过行列表作为元组构建 DataFrame:
>>> df = cudf.DataFrame([ ... (5, "cats", "jump", np.nan), ... (2, "dogs", "dig", 7.5), ... (3, "cows", "moo", -2.1, "occasionally"), ... ]) >>> df 0 1 2 3 4 0 5 cats jump <NA> <NA> 1 2 dogs dig 7.5 <NA> 2 3 cows moo -2.1 occasionally
从 Pandas DataFrame 转换:
>>> import pandas as pd >>> pdf = pd.DataFrame({'a': [0, 1, 2, 3],'b': [0.1, 0.2, None, 0.3]}) >>> pdf a b 0 0 0.1 1 1 0.2 2 2 NaN 3 3 0.3 >>> df = cudf.from_pandas(pdf) >>> df a b 0 0 0.1 1 1 0.2 2 2 <NA> 3 3 0.3
相关用法
- Python cudf.DataFrame.mod用法及代码示例
- Python cudf.DataFrame.isin用法及代码示例
- Python cudf.DataFrame.rmul用法及代码示例
- Python cudf.DataFrame.apply用法及代码示例
- Python cudf.DataFrame.exp用法及代码示例
- Python cudf.DataFrame.drop用法及代码示例
- Python cudf.DataFrame.where用法及代码示例
- Python cudf.DataFrame.median用法及代码示例
- Python cudf.DataFrame.to_pandas用法及代码示例
- Python cudf.DataFrame.take用法及代码示例
- Python cudf.DataFrame.tail用法及代码示例
- Python cudf.DataFrame.rfloordiv用法及代码示例
- Python cudf.DataFrame.equals用法及代码示例
- Python cudf.DataFrame.head用法及代码示例
- Python cudf.DataFrame.count用法及代码示例
- Python cudf.DataFrame.isna用法及代码示例
- Python cudf.DataFrame.groupby用法及代码示例
- Python cudf.DataFrame.round用法及代码示例
- Python cudf.DataFrame.cumsum用法及代码示例
- Python cudf.DataFrame.subtract用法及代码示例
注:本文由纯净天空筛选整理自rapids.ai大神的英文原创作品 cudf.DataFrame。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。