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 csvimport osimport pandas as pdos.chdir("C:\\Users\\khalha\\Desktop\\RealExcel")filename = "sales.csv"Sales = pd.read_csv("sales.csv")iFlowStatus = Sales.str.contains("iFlow")><"Status">print(iFlowStatus)

*

The error message means that the dataframe contains blank entries that default to na/NaN.

You are watching: Valueerror: cannot index with vector containing na / nan values

You can just add na=False in the synatx to fill value for missing values.

import csvimport osimport pandas as pdos.chdir("C:\\Users\\khalha\\Desktop\\RealExcel")filename = "sales.csv"Sales = pd.read_csv("sales.csv")iFlowStatus = Sales.str.contains("iFlow", na=False)><"Status">print(iFlowStatus)

*

*

One other possible issue: you can get this with mixed-type columns that do not contain NaN. For example:

> df = pd.DataFrame({"x": <"hi", 99>})> df.x.isna().any()False> df...ValueError: cannot index with vector containing NA / NaN valuesDepending on what you want to do, you can cast (df.x.astype(str).str.contains("hi")) or drop the offending rows.


*

Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

See more: The Norton Field Guide To Writing With Readings, The Norton Field Guide To Writing

To learn more, see our tips on writing great answers.


Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy


Not the answer you're looking for? Browse other questions tagged python excel string csv or ask your own question.


Constructing pandas DataFrame from values in variables gives "ValueError: If using all scalar values, you must pass an index"
*

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.10.4.40368


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.