Python 3.x 如果一行df导入失败,则索引被解释为浮点
这里是一个csv,我想使用熊猫导入Python 3.x 如果一行df导入失败,则索引被解释为浮点,python-3.x,csv,pandas,Python 3.x,Csv,Pandas,这里是一个csv,我想使用熊猫导入 Isolate,Sp 14E7,indet 我无法导入csv。14E7被解释为浮点,因此无法导入帧。如果在导入时尝试将其转换为字符串,则导入也会失败 df1 = pd.read_csv(infile, index_col=0, header=0, dtype=str) #I have also tried something like these but the import does not work at all then #converters={
Isolate,Sp
14E7,indet
我无法导入csv。14E7被解释为浮点,因此无法导入帧。如果在导入时尝试将其转换为字符串,则导入也会失败
df1 = pd.read_csv(infile, index_col=0, header=0, dtype=str)
#I have also tried something like these but the import does not work at all then
#converters={'Isolate': lambda x: str(x)}
#df1.index = df1.index.map(str)
我调用
BUG
解决问题
import pandas as pd
from io import StringIO
txt = """Isolate,Sp
14E7,indet"""
pd.read_csv(
StringIO(txt), header=0, converters={'Isolate': str}).set_index('Isolate')
Sp
Isolate
14E7 indet
您得到了哪些错误,您喜欢的输出是什么?