首页 > 解决方案 > 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)

标签: pythonexcelstringcsv

解决方案


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)

推荐阅读