{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# concat_with_column_name" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
abcdef
0012323
1123434
2234545
3345656
4456767
\n", "
" ], "text/plain": [ " a b c d e f\n", "0 0 1 2 3 2 3\n", "1 1 2 3 4 3 4\n", "2 2 3 4 5 4 5\n", "3 3 4 5 6 5 6\n", "4 4 5 6 7 6 7" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "\n", "s1 = pd.Series(range(5), name=\"a\")\n", "s2 = pd.Series(range(1, 6), name=\"b\")\n", "s3 = pd.Series(range(2, 7))\n", "s4 = pd.Series(range(3, 8))\n", "\n", "pd.concat([\n", " pd.concat(\n", " [\n", " pd.DataFrame(s1),\n", " s2.to_frame()\n", " ], axis=1\n", " ),\n", " pd.concat([s3, s4], keys=list(\"cd\"), axis=1),\n", " pd.DataFrame({\"e\": s3, \"f\": s4})\n", "], axis=1).head()\n", " " ] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "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.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }