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
Copy file name to clipboardExpand all lines: doc/source/cookbook.rst
+8-10Lines changed: 8 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1340,17 +1340,17 @@ Create two DataFrames with one column each from a subset of the unique values wi
1340
1340
1341
1341
.. ipython:: python
1342
1342
1343
-
df1.A.dtype
1343
+
df1.A.dtype
1344
1344
1345
1345
.. ipython:: python
1346
1346
1347
-
df2.A.dtype
1347
+
df2.A.dtype
1348
1348
1349
1349
.. ipython:: python
1350
1350
1351
-
df3.A.dtype
1351
+
df3.A.dtype
1352
1352
1353
-
The data type of all the columns is Object. Using Categorical columns should improve memory usage.
1353
+
The data type of all the columns is Object. Using Categorical columns should improve memory usage.
1354
1354
1355
1355
.. ipython:: python
1356
1356
@@ -1367,17 +1367,17 @@ The data type of all the columns is Object. Using Categorical columns should imp
1367
1367
.. ipython:: python
1368
1368
1369
1369
dfc3 = dfc1.append(dfc2)
1370
-
dfc3.memory_usage()
1370
+
dfc3.memory_usage()
1371
1371
1372
1372
.. ipython:: python
1373
1373
1374
1374
df3.A.dtype
1375
1375
1376
-
The first two Dataframes used a lot less memory because their columns are Categorical, but the column in the third Dataframe has a data type of Object and is using the same amount of memory as before. The appended category columns were converted into an object column because the columns' categories are incompatible:
1376
+
The first two Dataframes used a lot less memory because their columns are Categorical, but the column in the third Dataframe has a data type of Object and is using the same amount of memory as before. The appended category columns were converted into an object column because the columns' categories are incompatible:
1377
1377
1378
1378
.. ipython:: python
1379
1379
1380
-
dfc1.A.cat.categories
1380
+
dfc1.A.cat.categories
1381
1381
1382
1382
.. ipython:: python
1383
1383
@@ -1404,12 +1404,10 @@ This time the same categories are specified for both of the starting columns.
1404
1404
dfc3 = dfc1.append(dfc2)
1405
1405
dfc3.memory_usage()
1406
1406
1407
-
The resulting DataFrame's memory usage is far smaller now that the data type of the final column is Category. It worked as expected this time because the code --> category mapping was the same for both of the original columns, which carried over to the final column:
1407
+
The resulting DataFrame's memory usage is far smaller now that the data type of the final column is Category. It worked as expected this time because the code --> category mapping was the same for both of the original columns, which carried over to the final column:
1408
1408
1409
1409
.. ipython:: python
1410
1410
1411
1411
[(code, cat) for code, cat inenumerate(dfc3.A.cat.categories)]
1412
1412
1413
1413
`More information about categorical data <http://pandas.pydata.org/pandas-docs/stable/categorical.html>`__
0 commit comments