Justus Perlwitz

Memory Usage of Pandas Categoricals

A great method to improve memory usage of Pandas DataFrames is by converting columns with categorical variables to use the data type categorical. The Pandas documentation explains further how to use this data type in your columns here. In this article we want to explore what memory savings we can typically expect when working with them.

  1. Setup

First, we import Pandas, NumPy and Matplotlib. Furthermore, we adjust the maximum amount of rows shown when displaying Pandas DataFrames in Jupyter notebooks and the default figure size for Matplotlib.

%matplotlib inline
import string

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

pd.set_option('display.max_rows', 6)

plt.rcParams["figure.figsize"] = 10, 5

  1. Test Data

We will then create some test data. Since we are concerned with efficiently storing categorical variables, we will create random strings that we then put into a Pandas Series.

First, we define the function that creates n random words. Here, we simply choose random letters out of string.ascii_letters, which can be found in the Python 3 standard library. We also seed numpy.random with 1 just to get consistent results.

def random_words(n, word_length=8):
    np.random.seed(1)
    random_chars = np.random.choice(
        list(string.ascii_letters),
        (n, word_length),
    )
    return np.array([
        "".join(word)
        for i, word in enumerate(random_chars)
    ])

Let’s take a look at two example random words.

random_words(2)

Output:

array(['LRmijlfp', 'aqbmhTgz'], dtype='<U8')

We then move on to create the function that gives us a random Pandas Series of words. For this, we invoke the random_words function we created before and choose however many different words we need to create a Series of length length with n_categories different categories.

We also allow specifying a third argument called categorical, which will us to decide whether we want the data to be stored as plain Python objects or memory efficient Pandas categoricals. This is important for later benchmarking as we will see.

def random_words_series(length, n_categories, categorical=True):
    np.random.seed(1)
    categories = random_words(n_categories)
    words = np.random.choice(
        categories,
        length,
    )
    return pd.Series(
        words,
        dtype='category' if categorical else object,
    )

As an example, this is how it would look like to create a series of random words out of 3 different categories with total series length 6.

example = random_words_series(
    6, 3
)
example.to_frame()

Output:

0
0 aqbmhTgz
1 YuLsulQC
2 YuLsulQC
3 LRmijlfp
4 aqbmhTgz
5 aqbmhTgz

We can then easily see that this Series has exactly 3 categories by inspecting its .dtype attribute.

len(example.dtype.categories)

Output:

3

Now, to compare a few examples, we create Series with 3 different amounts of categories: 1, 10 and 100. Each Series will have a total length of 10000 values. Furthermore, for comparison we create each Series twice: once with the data type set to categorical and once to just using Python objects. We get 6 series in total.

The 3 series ending on _category contain data stored as category data in Pandas. The 3 series ending on _object contain data stored as Python objects.

n = 10000

series = {
    'one_category': random_words_series(
        n, 1,
    ),
    'several_categories': random_words_series(
        n, 10,
    ),
    'many_categories': random_words_series(
        n, 100,
    ),
    'one_object': random_words_series(
        n, 1, False,
    ),
    'several_objects': random_words_series(
        n, 10, False,
    ),
    'many_objects': random_words_series(
        n, 100, False,
    ),
}

After we have created the 6 different series using our random_words_series method, we want to move on to analyzing memory usage. This will allow us to find out how big the memory savings are.

  1. Memory

For each example series, we analyze the memory usage by using the standard Pandas .memory_usage() method. We print it out immediately.

memory_usage = pd.Series(
    {k: v.memory_usage(deep=True) for k, v in series.items()},
    name='memory_usage',
    dtype='uint64',
).sort_values()
memory_usage.to_frame()

Output:

memory_usage
one_category 10225
several_categories 11050
many_categories 21700
many_objects 650080
one_object 650080
several_objects 650080

We can see that category data in Pandas use considerably less memory than plain Python objects.

Furthermore, we print out a logarithmic plot of memory size for each Series.

fig, ax = plt.subplots()
ax.set_ylabel('Bytes')
memory_usage.to_frame().plot(
    kind='bar',
    logy=True,
    ax=ax,
);

Output:

<img alt=“<matplotlib.figure.Figure at 0x112f24908>” src=“data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYgAAAFQCAYAAAClLulkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3Xu8VXWd//HXGyQJQrwxXUQFk4sXUBMQsl9iTuYlDCwytNG8O6lgqWNe+mU1OmlOTWCNYgpFmaHoz2uT4mSZiQiKeMN0jBKdEhFBMRXk8/tjrQ3b42KfA2fvs/Za5/18PPbDs9c++5zP9hzOe6/v+n4/X0UEZmZ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y9/+QsA+++/P7169aJXr1707t2bMWPGADBkyBAWLlzIihUreOWVV9hvv/0AOOaYYxg/fvy6733EEUes+/iEE07g0ksvZezYsUybNo2rrrpqo1/LqFGjuOiii1iyZAmHH344AwYMAGDy5MncdNNNADz33HM8/fTT/PWvf2W//fZj6623BmD8+PH88Y9/BGD27Nk88cQT677uypUree2113jf+9630TWZWeMVMiAi4lbg1mHDhp2Ydy0bsvnmm6/7uEuXLuvud+nShTVr1tC1a1dmzZrFoEGD3vG8Bx54oNXntqZnz57rPt53331ZvHgx99xzD2+//Ta77777Bp+32WabsXbtWoB3rEU48sgj2Weffbj99ts55JBDuPLKK+nSpQuzZ8/m/vvvp0ePHowePbrV9Qtr165lzpw5dO/evdXXYGb58xBTTj71qU8xZcoUKu3WH3744TY/t3fv3my11Vbce++9AMyYMWPd2USWo48+miOPPJJjjz225tft168f8+fPB+CGG25Yd/zZZ59lp512YuLEiXzmM59Zdxaz1VZb0aNHDxYtWsScOXMAGD58OL/97W9Zvnw5a9asYdasWeu+zoEHHsiUKVPW3V+wYEGbX7OZdbxCnkFsjGadlvr1r3+dM844g6FDh7J27Vr69+/Pbbfd1ubn/+QnP+GUU07h9ddfZ6eddmLatGkb/NyjjjqKCy64gAkTJtT8mmeddRaf//znmTp1Koceuv7/28yZM5kxYwbdunXjAx/4AOeddx49e/bkiiuuYJdddmHQoEGMHDkSgO22247zzjuPESNGsPXWWzN48GAqCxonT57MqaeeytChQ1mzZg0f//jHueKKK9r8ms2sY5Vuw6Ann3ySXXbZJaeKmtMNN9zAzTffzIwZMzrk+1WuK6xZs4Zx48Zx3HHHMW7cuDY/vzP/DMs2j74lv7762tTX19YNg0p/BtHZnX766fzqV7/ijjvu6LDveeGFFzJ79mzeeOMNDjzwQMaOHdth39vM6scBUXLVY/4Vp5566rvWIEyaNKnVaxRtVZmZZWbF5oDohH74wx/mXYKZFUApZzEV+bpKZ+efnVnzKGRA1NoPonv37ixbtsx/aAqosmGQ10mYNYdCDjHVWijXt29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IKzpx0HbyRvqWLOqvBE7lKS78O3Ae3Ks5108zbWTk7Q3MBnYHXiMdBw0IhbmWlidSBpO0oxwS5INdbYALo2IB3ItzDo9SbcBzwOfBD4C/B2YGxF75FpYFQeENX1P+vaQNIxkz9/qDXW80thyJ6kHcBDwaEQ8LemDwJCIuDPn0tZxQHRyRehJ3x7eUMds0zkgOrkW3STXkqyonhkRf8m1sDqR9PuI+Fjrn2lmLTkgbJ1m7UnfHpIOINlmtGWrjRtzK8qsIJpqzq3lo9l70rfTsSQb6nSjakMdwAFh1gqfQXRyLXrS/7IZe9K3h6SnvKGO2abxGYQd3ew96dvJG+qYbSIHhL0i6WpK2osJGAkskOQNdcw2koeYOrki9KRvD2+oY7bpfAZhTd+Tvj0cBGabzr2YrOy9mMxsE/kMwpq+J72Z5cNnENb0PenNLB8OCGv6nvRmlg8HhDV9T3ozy4cDwp6XdCVJm407JG2Ofy/MDK+D6PSK0JPezPLhgDAzs0weSjAzs0wOCDMzy+SAMDOzTA4IMzPL5IAwM7NM/x+NZoJ7VAk/UAAAAABJRU5ErkJggg==”/>

Finally, we will try to see how memory usage behaves when the amount of different categories inside a Series grows.

  1. Memory usage as function of size

For this analysis, we will create 2000 series with up to 2000 different categories. As before, in order to allow us to understand the memory usage of category data in Pandas, we create the series once using the Pandas category data type and once just using plain Python objects.

First, we calculate the memory usage for the plain Python object series:

size_n = 2000
size = pd.Series(
    {
        i: random_words_series(
            size_n, i, False,
        ).memory_usage(deep=True)
        for i in range(1, size_n + 1)
    },
    name="Memory usage for n categories (object data type)",
).sort_values()

Right after that, we calculate the memory usage for all of the categorical series:

size_categorical = pd.Series(
    {
        i: random_words_series(
            size_n, i,
        ).memory_usage(deep=True)
        for i in range(1, size_n + 1)
    },
    name="Memory usage for n categories (categorical data type)",
).sort_values()

Now, we can put the sizes next to each other in a Pandas DataFrame. We will immediately see that despite the number of categories nearing 2000, the memory usage never comes close to that of the Series using plain Python objects.

sizes = pd.DataFrame([size, size_categorical]).T
sizes

Output:

Memory usage for n categories (object data type) Memory usage for n categories (categorical data type)
1 130080 2225
2 130080 2290
3 130080 2355
1998 130080 127460
1999 130080 127395
2000 130080 127460

We can plot these values against each other. Since the Python object Series always contain the same amount of data regardless of the number of categories we see that the memory usage is constant as well. For the category data type series we clearly see an increase in memory usage, but it never touches the constant line of the Python object series in the plot.

fig, ax = plt.subplots(1)
ax.set_xlabel('Random Words')
ax.set_ylabel('Bytes')
sizes.plot(
    ax=ax
);

Output:

<img alt=“<matplotlib.figure.Figure at 0x113660550>” src=“data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZsAAAEKCAYAAADEovgeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3Xl4FFX28PHvYV9kExBR0ERFEchKQBDZRHYEFFERkEXFHRjHBd8RYcZlVBxR3H7iSAB1AIFRGMVhG6KioAQFlEVECBJElgBhDVn6vH9UpdMJCUlIujsJ5/M8/aTrVnXVqepOn75Vt+4VVcUYY4zxp3LBDsAYY0zZZ8nGGGOM31myMcYY43eWbIwxxvidJRtjjDF+Z8nGGGOM31myMcYY43eWbIwxxvidJRtjjDF+VyHYAZQU9erV05CQkGCHYYwxpcratWsPqGr9/JazZOMKCQkhPj4+2GEYY0ypIiI7C7KcnUYzxhjjd5ZsjDHG+J0lG2OMMX5nycYYY4zfWbIxxhjjd5ZsjDHG+J0lG2OMMX5n99kU0fLNe1m/63CwwzDGmLN2U3QjQutV9+s2LNkU0Rdb9/P+6gLd02SMMSVS9KV1/J5sRFX9uoHSIiYmRq0HAWOMKRwRWauqMfktZ9dsjDHG+J2dRjPGmLJq5zcQ2zNruvYl0HsylCsHnz4CNRrCld2g+U1QJ8SvoViyMcaYskYVvpwEK57LXn74N/hwQNb0oR3w2zfQIMySjTHGmELa8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bzC+xdoBQ4HrRWSd++gFvAB0FZFfgBvcaYBFwHZgG/Au8ACAqh4EngHWuI+/uWW4y/zTfc2vwOeB2LEiSznsXJ85rwHUv6pYajMiwpAhQ7zT6enp1K9fnz59+hR53WXVY489RvPmzXnssceCHYpXQkIC//rXvwKyraeffpply5YVeT0//PADd9111xmXmThxIi+//PJp5b///ju33HLLWW13+vTp/P777/kul5CQQIsWLfJdprDH/fDhw7z11luFek1B3XDDDRw6dMgv6/a3YLRGW6mqoqrhqhrpPhapapKqdlHVJqp6Q2bicFuhPaiql6tqmKrG+6xrmqpe4T5ifcrjVbWF+5qH3FZpJZ8n3fl7XgOQ4nlrqlevzk8//cTJkycBWLp0KRdfnGt7Cb9JT08P6PaKaurUqWzYsIFJkyYVaPlA7F+gkk1GRgZ/+9vfuOGGG4q8rueff57Ro0ef1Wsvuugi5s2bd1avLWiyKYiSlmyGDh3qt3X7m52fKUk8HudvMSWaTL169eKzzz4DYNasWQwaNMg77/jx44wcOZLWrVsTFRXFggXOGcfp06fTv39/unbtSkhICG+88QavvPIKUVFRtGnThoMHnUrkunXraNOmDeHh4dx0003eX12dOnVi7NixxMTE8NwfOkgxAAAdkklEQVRzzxEaGkpaWhoAR44cyTadafjw4dm+YM47z2navWfPHjp06EBkZCQtWrTgq6++AuD+++8nJiaG5s2bM2HCBO/rFi1aRNOmTWnZsiWjR4/21uLy2ldfffv25dixY7Rs2ZI5c+aQkJDA9ddfT3h4OF26dOG3337zxnrfffdxzTXX8Pjjj2dbx/Tp07n55pvp0aMHTZo0OW1+pjVr1nDttdcSERFB69atOXr0KAkJCbRv357o6Giio6P55ptvABg3bhxfffUVkZGRTJ48mYyMDB577DFatWpFeHg477zzDgAej4cHHniApk2b0rVrV3r16uU9psuXLycqKoqwsDBGjhzJqVOnAAgJCeGJJ54gOjqauXPnZnsf1q5dS8eOHWnZsiXdu3dnzx6nweiUKVNo1qwZ4eHh3H777aft29GjR9mwYQMREREAHDx4kP79+xMeHk6bNm3YsGGD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o1atXtnlLlixh4cKF3vPmKSkp3l/vnTt3pkaNGtSoUYNatWpx4403AhAWFsaGDRtITk7m8OHDdOzYEYBhw4YxcOBA77pvu+027/O7776bl156if79+xMbG+v9BVsQrVq1YuTIkaSlpdG/f38iIyMB+Oijj5g6dSrp6ens2bOHTZs24fF4uOyyy7zNMwcNGsTUqVPPuK9XX311nttetWoV//6302By6NCh2WopAwcOpHz58rm+rkuXLtSqVQuAZs2asXPnTho3zmo8+fPPP9OwYUNatWoFQM2aNQGn9vXQQw+xbt06ypcvz9atW3Nd/5IlS9iwYYO3BpKcnMwvv/zCypUrGThwIOXKlePCCy+kc+fO3u2FhoZy5ZVXAs579eabbzJ27Fgg+3vlG+NPP/1E165dAaeG0bBhQ8D5TA0ePJj+/fvTv//p90zv2bOH+vXre6dXrlzJ/PnzAbj++utJSkriyJEjAPTr14+qVatStWpVOnfuzHfffed9j8+0r8uWLWPEiBFUq1YNgPPPPz/XY5Xp8OHDHD58mA4dOgDO+/n5587l3LS0tAId94Iu56tjx4488MAD7N+/n/nz5zNgwAAqVHC+ert27UrdunUBuPnmm1m5ciUVKlRg7dq13s/GyZMnueCCC7zru+CCC/j999+9rystLNkEyIQbm59emJ4CSb86yaZaPbflWe5fXkXVt29fHn30UeLi4khKSvKWqyrz58/nqquuyrb8t99+S+XKlb3T5cqV806XK1euQNcpqlfPauDQrl07EhISiIuLIyMjI9cLsxUqVMDjnkr0eDykpqYC0KFDB7788ks+++wzhg8fziOPPEL79u15+eWXWbNmDXXq1GH48OH5NsvMa1/Plu/+5eR77MqXL1/g6zqTJ0+mQYMGrF+/Ho/HQ5Uquf/4UFVef/11unfvnq180aJFBdpOTrnti6rSvHlzVq1addq8zz77jC+//JL//Oc/PPfcc/z444/eL1CAqlWrFriZbM5WTjmn89rXxYsXF2j9BVHQ417Q5XK68847+eCDD5g9ezaxsd7Ly7nuu6oybNgw/v73v+e6rpSUFKpWrVrAPSs57JpNMJ046CSauldA7cZ+SzQAI0eOZMKECYSFhWUr7969O6+//jrqtqH44YcfCrzOWrVqUadOHe81lPfff99by8nNnXfeyR133MGIESNynR8SEsLatWsBWLhwofeazs6dO2nQoAH33HMPd999N99//z1HjhyhevXq1KpVi71793p/oV511VVs376dhIQEAObMmVOkfb322muZPXs2AB9++CHt27fP9zUFcdVVV7Fnzx7WrFkDONc40tPTSU5OpmHDhpQrV47333/fe66+Ro0aHD16NNu+vP32295jtHXrVo4fP067du2YP38+Ho+HvXv3EhcX591eQkIC27ZtA/J/rzJfs3//fm+ySUtLY+PGjXg8Hnbt2kXnzp158cUXSU5O5tixY9lee/XVV3u3BdC+fXs+/PBDAOLi4qhXr563NrdgwQJSUlJISkoiLi7O+4s+v33t2rUrsbGxnDhxAsB7HTHnscpUu3ZtateuzcqVKwG88QAFPu55Lecrt+0PHz6cV199FXBqupmWLl3KwYMHOXnyJJ988gnt2rWjS5cuzJs3j3379nn3a+fOnYCTeP/44w9CQkJO225JZzWbYFIPSHmoXMPvm2rUqFGuLYPGjx/P2LFjCQ8Px+PxEBoayqefflrg9c6YMYP77ruPEydOcNlll2X71ZbT4MGDeeqpp7I1UPB1zz330K9fPyIiIujRo4f313ZcXByTJk2iYsWKnHfeecycOZPQ0FCioqJo2rQpjRs3pl27doDzi/qtt97yvt73i+ts9vX1119nxIgRTJo0ifr1659x/wqjUqVKzJkzh4cffpiTJ09StWpVli1bxgMPPMCAAQOYOXNmtmMQHh5O+fLliYiIYPjw4YwZM4aEhASio6NRVerXr88nn3zCgAEDWL58Oc2aNaNx48ZER0dTq1YtqlSpQmxsLAMHDiQ9PZ1WrVpx33335RvjvHnzGD16NMnJyaSnpzN27FiuvPJKhgwZQnJyMqrK6NGjqV27drbXNm3alOTkZI4ePUqNGjWYOHEiI0eOJDw8nGrVqjFjxgzvsuHh4XTu3JkDBw4wfvx4LrroIhISEry/+u++++5c97VHjx6sW7eOmJgYKlWqRK9evXj++ee9jTeqVq3KqlWrstUCYmNjGTlyJCJCt27dvOUFPe55Leerbt26tGvXjh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iEgVd14LnD61WgHPASfU6bhxFU43Jjl9TVZyuQync9EYd/panGQETrf1T6hqOM4d4hN81lFJVWNU9R/Aa8Dbbmy+XQbdASxW1UggAueOdGMKzJKNMdlVFWdkxczu15e65QI8LyIbcLr5uJis7tl3qGrml+9aIMS91lNbnfFOwOlaJdN1wAcAqroF2InTISPAClU9qqr7gWTgP275jziDb+X0DXCt2wdYgqqm4HSNdR7QEvhWRGq5sXzhvmYGzqBfmeb4PG9HVr9xvjGvAUaIyEQgTJ0xUowpMEs2xmR30v31filOgsk8/TUYqA+0dOfvBTJrI6d8Xp8BFOXah++6PD7TntzWq85YKbWBG3FqP+AkvBE4yacgF/iP51xtLtv5EidB7Qami0hutSxj8mTJxphcqNO78Wjgz+6F81rAPlVNc6+xXJrP6w8Dh0XkOrdosM/srzKnReRK4BKcDiPP1mpgDFnJZhUwFvd6jaomA4d8rrMMBb7IuRLX1zi9IWeLWUQuxRkI7F3gnzhDIRtTYJZsjMmDqv6A02vuIJwBw2JE5EecaydbCrCKEcCb7mk58Sl/CyjnrmsOMFxVT+W2ggL6GmfMkXh3ehXO9ZtvfJYZBkxyTwNGAn/LY11jcAa7+5HsIzJ2AtaLyA/AbTjXdowpMOv12RhjjN9ZzcYYY4zfWbIxxhjjd5ZsjDHG+J0lG2OMMX5nycYYY4zfWbIxxhjjd5ZsjDHG+J0lG2OMMX73/wHC6Jez3YDJegAAAABJRU5ErkJggg==”/>

At this point we should ask ourselves whether string data should always be stored as categorical data in Pandas. While one would assume that the added indirection should provide no advantage when using non-categorical values, the memory usage analysis here implies otherwise. We need to further inspect whether the method to determine memory usage is sound, i.e. whether Pandas .memory_usage(deep=True) correctly takes in account all nested data. On the other hand, with a low number of categories the memory savings are quite significant. Here it always makes sense to switch the data type to categorical.

To sum it up: If category data is encountered, the Pandas category data type should always be used.

Date created:
23 Feb 2018

You are more than welcome to share your thoughts via email