Skip to content

Instantly share code, notes, and snippets.

@cryptowen
Created February 21, 2017 15:06
Show Gist options
  • Save cryptowen/0f94d6679d34d9d5ffaaba7690b42aef to your computer and use it in GitHub Desktop.
Save cryptowen/0f94d6679d34d9d5ffaaba7690b42aef to your computer and use it in GitHub Desktop.
convert value to demical when read_csv in pandas
# -*- coding: utf-8 -*-
import pandas as pd
import io
import decimal as D
temp = u"""a,b,c,d
0.1,0.2,0.1,0.2"""
df = pd.read_csv(
io.StringIO(temp), converters={'c': D.Decimal,
'd': D.Decimal})
for i, v in df.iterrows():
print(type(v.a), type(v.b), type(v.c), type(v.d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment