Python:从Excel文件中将大量数字导出为字符串
尝试从excel文件获取列时,此列的值为=8191958616457289553213234621044503745。当我得到dataframe设备列时,将所有值更改为:8.19195861645729e+17,2.132346210445037e+17,即使我更改为str或将其放入:Python:从Excel文件中将大量数字导出为字符串,python,excel,pandas,Python,Excel,Pandas,尝试从excel文件获取列时,此列的值为=8191958616457289553213234621044503745。当我得到dataframe设备列时,将所有值更改为:8.19195861645729e+17,2.132346210445037e+17,即使我更改为str或将其放入: File['device'] = File.apply(lambda x: "'" + str(x.device) , axis = 1) 值总是以错误的格式显示 代码如下: import
File['device'] = File.apply(lambda x: "'" + str(x.device) , axis = 1)
值总是以错误的格式显示
代码如下:
import pandas as pd
NewFilePath =r'C:\Users\318459\Downloads\\'#AQUI CAMBIO
NewFile='AAACB Main 5.7.2021.xlsx' #AQUI CAMBIO
NewFilePath =NewFilePath.replace('\\', '/')
File= pd.read_excel(f'{NewFilePath}{NewFile}', sheet_name="Sheet1")
File['device']=File['device'].values.astype(str)
File=File[['device']]
关于导入数据时,您需要停止pandas推断数据类型,否则就太晚了。为此,请在导入时指定
dtype
File = pd.read_excel(f'{NewFilePath}{NewFile}', sheet_name='Sheet1',
dtype={'device': 'str'})