Sign Up

Sign In

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask question.

ValueError: cannot index with vector containing NA / NaN values

  • 4

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)
Share

1 Answer

  1. @HarisKhaliq, I will answer this question because it will benefit other people.
    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)
    
    .
    
    • 0
Leave an answer

Leave an answer

Browse

close