. Advertisement .
..3..
. Advertisement .
..4..
I am tired of fixing the problem: valueerror: cannot index with vector containing na / nan values in the python; even if I get the reference from another forum, it still returns an error:
ValueError: cannot index with vector containing NA / NaN values
To identify the problem, I will show you the detail here:
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)
How do I do that? Could you support me in improving this problem?
The cause:
You have got ”cannot index with vector containing na / nan values” error because your dataframe includes empty entries which always set default to NA or NaN.
Solution:
You can solve this error simply by adding
na=False
in the synatx to fill the missing or lost values as the following:Another issue is that mixed-type columns can cause this problem if they do not contain NaN. Take this example:
Depending on your intent, you have the option to cast (
df.x.astype(str).str.contains('hi')
), or drop the row that is not working.