【问题标题】:Decimal values getting scientific notation in Python在 Python 中获取科学记数法的十进制值
【发布时间】:2021-04-01 11:42:20
【问题描述】:

我正在尝试通过 python 将 csv 文件加载到 sql server。将 csv 加载到 sql 是由不同的工具完成的,我的问题是字段宽度没有得到扩展,让我的文件中的十进制值得到科学记数法。我尝试以 xlsx 格式保存文件并扩展字段宽度,当我使用 pandas 导入时,我仍然可以看到十进制整数长度被截断。

my excel( csv ) contains values of this format when expanded the col width
val             val 2
0.00000141     a
0.0000011      b
 
when not expanded
1.41E-6        a
1.1E-06        b

如何在不丢失数据的情况下将这些加载到 sql server?

The code i use for loading to sql is quite straightforward

df= pd.read_csv(read my file)
engine= sql.create_engine("mssql+pyodbc://mydbname",fast_executemany=True)
df.to_sql("mytablename", engine, schema='dbo', if_exists='replace', index=False, chunksize=500)

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    你可以试试:

    import pandas as pd
    pd.set_option('display.float_format', lambda x: '%.8f' % x)  # Eight digits after the comma 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多