python 在pandas中的read_csv时将值转换为demical

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 在pandas中的read_csv时将值转换为demical相关的知识,希望对你有一定的参考价值。

# -*- 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))

以上是关于python 在pandas中的read_csv时将值转换为demical的主要内容,如果未能解决你的问题,请参考以下文章