Skip to content

Instantly share code, notes, and snippets.

@lumbric
Created March 31, 2020 17:14
Show Gist options
  • Save lumbric/8d197e2014e203d6dc6427f409ff9b95 to your computer and use it in GitHub Desktop.
Save lumbric/8d197e2014e203d6dc6427f409ff9b95 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"text = 'a' * 10000\n",
"d = pd.DataFrame({'a': [text] *30_000})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Feather"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"865 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
]
}
],
"source": [
"%timeit -n1 -r1 d.to_feather('/tmp/a.feather')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"92.7 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
]
}
],
"source": [
"%timeit -n1 -r1 pd.read_feather('/tmp/a.feather')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-r--r-- 1 peter peter 287M Mär 31 19:10 \u001b[0m\u001b[00m/tmp/a.feather\u001b[0m\r\n"
]
}
],
"source": [
"ls -lh /tmp/a.feather"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### CSV"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6.48 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
]
}
],
"source": [
"%timeit -n1 -r1 d.to_csv('/tmp/a.csv')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.88 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
]
}
],
"source": [
"%timeit -n1 -r1 pd.read_csv('/tmp/a.csv')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 peter peter 287M Mär 31 19:10 \u001b[0m\u001b[00m/tmp/a.csv\u001b[0m\r\n"
]
}
],
"source": [
"ls -lh /tmp/a.csv"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### HDF"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"190 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
]
}
],
"source": [
"%timeit -n1 -r1 d.to_hdf('/tmp/a.hdf', 'key')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9.73 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n"
]
}
],
"source": [
"%timeit -n1 -r1 pd.read_hdf('/tmp/a.hdf', 'key')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-rw-rw-r-- 1 peter peter 58M Mär 31 19:10 \u001b[0m\u001b[00m/tmp/a.hdf\u001b[0m\r\n"
]
}
],
"source": [
"ls -lh /tmp/a.hdf"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment