You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# this is lower-common-denomicator upcasting (meaning you get the dtype which can accomodate all of the types)
1065
+
The ``values`` attribute on a DataFrame return the *lower-common-denominator* of the dtypes, meaning the dtype that can accomodate **ALL** of the types in the resulting homogenous dtyped numpy array. This can
1066
+
force some *upcasting*.
1067
+
1068
+
.. ipython:: python
1069
+
1028
1070
df3.values.dtype
1029
1071
1030
-
Astype
1072
+
astype
1031
1073
~~~~~~
1032
1074
1033
1075
.. _basics.cast:
@@ -1044,7 +1086,7 @@ then the more *general* one will be used as the result of the operation.
1044
1086
# conversion of dtypes
1045
1087
df3.astype('float32').dtypes
1046
1088
1047
-
Object Conversion
1089
+
object conversion
1048
1090
~~~~~~~~~~~~~~~~~
1049
1091
1050
1092
To force conversion of specific types of number conversion, pass ``convert_numeric = True``.
@@ -1067,16 +1109,19 @@ the objects in a Series are of the same type, the Series will have that dtype.
1067
1109
df3['E'] = df3['E'].astype('int32')
1068
1110
df3.dtypes
1069
1111
1070
-
# forcing date coercion
1112
+
This is a *forced coercion* on datelike types. This might be useful if you are reading in data which is mostly dates, but occasionally has non-dates intermixed and you want to make those values ``nan``.
1113
+
1114
+
.. ipython:: python
1115
+
1071
1116
s = Series([datetime(2001,1,1,0,0), 'foo', 1.0, 1, Timestamp('20010104'), '20010105'],dtype='O')
1072
1117
s
1073
1118
s.convert_objects(convert_dates='coerce')
1074
1119
1075
1120
1076
-
Upcasting Gotchas
1077
-
~~~~~~~~~~~~~~~~~
1121
+
gotchas
1122
+
~~~~~~~
1078
1123
1079
-
Performing indexing operations on ``integer`` type data can easily upcast the data to ``floating``.
1124
+
Performing selection operations on ``integer`` type data can easily upcast the data to ``floating``.
1080
1125
The dtype of the input data will be preserved in cases where ``nans`` are not introduced (starting in 0.11.0)
1081
1126
See also :ref:`integer na gotchas <gotchas.intna>`
0 commit comments