python - ValueError: cannot index with vector containing NA / NaN values
问题描述
I do not understand why I am receiving the error listed in the title, the value that I am intending to return is the number 30
import csv
import os
import pandas as pd
os.chdir('C:\\Users\\khalha\\Desktop\\RealExcel')
filename = 'sales.csv'
Sales = pd.read_csv('sales.csv')
iFlowStatus = Sales[Sales['Product'].str.contains('iFlow')]['Status']
print(iFlowStatus)
解决方案
The error message means that the dataframe contains blank entries that default to na/NaN.
You can just add na=False
in the synatx to fill value for missing values.
import csv
import os
import pandas as pd
os.chdir('C:\\Users\\khalha\\Desktop\\RealExcel')
filename = 'sales.csv'
Sales = pd.read_csv('sales.csv')
iFlowStatus = Sales[Sales['Product'].str.contains('iFlow', na=False)]['Status']
print(iFlowStatus)
推荐阅读
- python - 提高 Spark.SQL 中的数据整理性能
- python - 能量分配中的成本最小化问题
- c++ - snprintf 的交叉编译版本在字符串缓冲区中分配适量的内存
- python-3.x - 在不知道键名的情况下从复杂的字典列表中删除键
- java - 以模块化实现方式更换开关
- javascript - Angular Material - 比较和迭代两个数据源
- excel - 如何使用 VBA 在 Excel 中查找特定列并复制粘贴相应的列
- flutter - ListView 中单元格之间出现意外的水平线
- sql - 如何获取 Table_A 中具有 X 引用数的 Table_B 中的条目计数
- vue.js - vue-router中的scrollBehavior,返回循环数据的位置