{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 1,000,000\n", "1 1,000\n", "2 1\n", "dtype: object\n" ] } ], "source": [ "s_sep = pd.Series(['1,000,000', '1,000', '1'])\n", "print(s_sep)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# print(s_sep.astype(int))\n", "# ValueError: invalid literal for int() with base 10: '1,000,000'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 1000000\n", "1 1000\n", "2 1\n", "dtype: int64\n" ] } ], "source": [ "print(s_sep.str.replace(',', '').astype(int))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 1000000.0\n", "1 1000.0\n", "2 1.0\n", "dtype: float64\n" ] } ], "source": [ "print(s_sep.str.replace(',', '').astype(float))" ] } ], "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.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }