用法:
DataFrame.astype(dtype, copy=False, errors='raise', **kwargs)將 DataFrame 轉換為給定的 dtype
- dtype:數據類型,或列名的字典 -> 數據類型
 使用 numpy.dtype 或 Python 類型將整個 DataFrame 對象轉換為相同類型。或者,使用
{col: dtype, ...},其中 col 是列標簽,dtype 是 numpy.dtype 或 Python 類型,將 DataFrame 的一個或多個列轉換為 column-specific 類型。- copy:布爾值,默認為 False
 當
copy=True時返回 deep-copy 。請注意,默認使用copy=False設置,因此對值的更改可能會傳播到其他 cudf 對象。- errors:{‘raise’, ‘ignore’, ‘warn’},默認 ‘raise’
 控製對提供的 dtype 的無效數據引發異常。
raise: 允許引發異常ignore:抑製異常。出錯時返回原始對象。warn:將最後的異常打印為警告並返回原始對象。
- **kwargs:傳遞給構造函數的額外參數
 
- casted:DataFrame
 
參數:
返回:
例子:
>>> import cudf >>> df = cudf.DataFrame({'a': [10, 20, 30], 'b': [1, 2, 3]}) >>> df a b 0 10 1 1 20 2 2 30 3 >>> df.dtypes a int64 b int64 dtype: object將所有列轉換為
int32:>>> df.astype('int32').dtypes a int32 b int32 dtype: object使用字典將
a轉換為float32:>>> df.astype({'a': 'float32'}).dtypes a float32 b int64 dtype: object >>> df.astype({'a': 'float32'}) a b 0 10.0 1 1 20.0 2 2 30.0 3
相關用法
- Python cudf.DataFrame.asin用法及代碼示例
 - Python cudf.DataFrame.assign用法及代碼示例
 - Python cudf.DataFrame.apply用法及代碼示例
 - Python cudf.DataFrame.apply_rows用法及代碼示例
 - Python cudf.DataFrame.all用法及代碼示例
 - Python cudf.DataFrame.add用法及代碼示例
 - Python cudf.DataFrame.abs用法及代碼示例
 - Python cudf.DataFrame.apply_chunks用法及代碼示例
 - Python cudf.DataFrame.atan用法及代碼示例
 - Python cudf.DataFrame.acos用法及代碼示例
 - Python cudf.DataFrame.any用法及代碼示例
 - Python cudf.DataFrame.append用法及代碼示例
 - Python cudf.DataFrame.argsort用法及代碼示例
 - Python cudf.DataFrame.mod用法及代碼示例
 - Python cudf.DataFrame.isin用法及代碼示例
 - Python cudf.DataFrame.rmul用法及代碼示例
 - Python cudf.DataFrame.exp用法及代碼示例
 - Python cudf.DataFrame.drop用法及代碼示例
 - Python cudf.DataFrame.where用法及代碼示例
 - Python cudf.DataFrame.median用法及代碼示例
 
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.DataFrame.astype。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
