Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/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-Pandas.ExcelFile()在少数情况下返回错误的数字_Python_Excel_Pandas - Fatal编程技术网

Python-Pandas.ExcelFile()在少数情况下返回错误的数字

Python-Pandas.ExcelFile()在少数情况下返回错误的数字,python,excel,pandas,Python,Excel,Pandas,我在编码方面是个新手,我面临着一个我自己无法解决的问题 我使用的是熊猫,在下面的代码中,打印的列表在80-90%的时间内返回正确的数字,并且在少数情况下会返回一个不知从何而来的不同数字 我的想法是熊猫不能很好地阅读excel,我将不得不使用csv,但我在excel文件中使用多个选项卡,我想让它工作 你有什么建议吗?非常感谢 import pandas as pd # Read the Excel and create a Dataframe xl = pd.ExcelFile("data_so

我在编码方面是个新手,我面临着一个我自己无法解决的问题

我使用的是熊猫,在下面的代码中,打印的列表在80-90%的时间内返回正确的数字,并且在少数情况下会返回一个不知从何而来的不同数字

我的想法是熊猫不能很好地阅读excel,我将不得不使用csv,但我在excel文件中使用多个选项卡,我想让它工作

你有什么建议吗?非常感谢

import pandas as pd

# Read the Excel and create a Dataframe
xl = pd.ExcelFile("data_source.xlsx")
df = xl.parse(paris)

# Creating the list of vehicle id and rate plan id
list_vehicle_type_id = df['vehicle_type_id'].dropna().astype('int').abs().tolist()
list_plan_id = df['plan_id'].dropna().astype('int').abs().tolist()

print(list_vehicle_type_id)
print(list_plan_id)
我发现了这个问题:

# Read the Excel and create a Dataframe
xl = pd.ExcelFile("data_source.xlsx")
df = xl.parse(country_choice)

# Creating the list of vehicle id and rate plan id
list_vehicle_type_id = df['vehicle_type_id'].dropna().astype('int').abs().tolist()

list_plan_id = df['plan_id'].dropna().tolist() # Creating a list of plan id as float
list_plans_int = [] # Creating an empty list
for i in list_plan_id: # Creating a loop to extract the list of plan id as float one by one and add it to the empty list as integer
    id_int =  int(i)
    list_plans_int.append(id_int)

为什么不使用熊猫。请阅读csv?哇,对不起,错误的代码我编辑了它是一个excel文件,只是为了理解为什么要使用
.dropna()
,这可能是问题()您是否有一个未正确返回值的最小示例?一旦临时删除
astype('int').abs()
,这些值会发生什么变化?也许excel将这些值存储为混合类型,而pandas在正确转换它们时遇到了一些问题。@Dadep因为当我创建df['plan_id']时,它会返回一些NaN。