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)
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[df.x.str.contains('hi')] ... ValueError: cannot index with vector containing NA / NaN values
Depending on what you want to do, you can cast (df.x.astype(str).str.contains('hi')
) or drop the offending rows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With