Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:从Excel文件中将大量数字导出为字符串_Python_Excel_Pandas - Fatal编程技术网

Python:从Excel文件中将大量数字导出为字符串

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

尝试从excel文件获取列时,此列的值为=8191958616457289553213234621044503745。当我得到dataframe设备列时,将所有值更改为:8.19195861645729e+17,2.132346210445037e+17,即使我更改为str或将其放入:

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'})