From c40836d38113b900f5201ed06781bfa72f7719e0 Mon Sep 17 00:00:00 2001 From: Steven Nicolaou Date: Fri, 21 Jun 2019 21:03:41 -0400 Subject: [PATCH 1/2] DOC: df.astype example using dictionary (#26990) --- pandas/core/generic.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 360576ffdb00a..006cd9dfd597a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5622,6 +5622,31 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs): Examples -------- + Create a DataFrame: + + >>> d = {'col1': [1, 2], 'col2': [3, 4]} + >>> df = pd.DataFrame(data=d) + >>> df.dtypes + col1 int64 + col2 int64 + dtype: object + + Cast all columns to int32: + + >>> df.astype('int32').dtypes + col1 int32 + col2 int32 + dtype: object + + Cast col1 to int32 using a dictionary: + + >>> df.astype({'col1': 'int32'}).dtypes + col1 int32 + col2 int64 + dtype: object + + Create a series: + >>> ser = pd.Series([1, 2], dtype='int32') >>> ser 0 1 From c2d1702734df97984b7a432c12e11209293d50c3 Mon Sep 17 00:00:00 2001 From: Steven Nicolaou Date: Fri, 21 Jun 2019 23:19:43 -0400 Subject: [PATCH 2/2] DOC: df.astype example using dictionary (#26990) --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 006cd9dfd597a..b08c101356157 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5640,7 +5640,7 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs): Cast col1 to int32 using a dictionary: - >>> df.astype({'col1': 'int32'}).dtypes + >>> df.astype({'col1': 'int32'}).dtypes col1 int32 col2 int64 dtype: object