There’s a flag for that:
In [11]: df = pd.DataFrame([["foo1"], ["foo2"], ["bar"], [np.nan]], columns=['a']) In [12]: df.a.str.contains("foo") Out[12]: 0 True 1 True 2 False 3 NaN Name: a, dtype: object In [13]: df.a.str.contains("foo", na=False) Out[13]: 0 True 1 True 2 False 3 False Name: a, dtype: bool
See the str.replace
docs:
na : default NaN, fill value for missing values.
So you can do the following:
In [21]: df.loc[df.a.str.contains("foo", na=False)] Out[21]: a 0 foo1 1 foo2
Related Posts:
- Renaming column names in Pandas
- Delete a column from a Pandas DataFrame
- How to deal with SettingWithCopyWarning in Pandas
- How to deal with SettingWithCopyWarning in Pandas
- How to iterate over rows in a DataFrame in Pandas
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Writing a pandas DataFrame to CSV file
- Adding new column to existing DataFrame in Python pandas
- Modifing data while using iterrows() does not work
- ImportError: No module named pandas
- How to change the order of DataFrame columns?
- How to change the order of DataFrame columns?
- What does `ValueError: cannot reindex from a duplicate axis` mean?
- How can I use the apply() function for a single column?
- Convenient way to deal with ValueError: cannot reindex from a duplicate axis
- How to fix IndexError: invalid index to scalar variable
- Merging dataframes on index with pandas
- Create a Pandas Dataframe by appending one row at a time
- Convert Python dict into a dataframe
- re.sub erroring with “Expected string or bytes-like object”
- How do I select rows from a DataFrame based on column values?
- How do I select rows from a DataFrame based on column values?
- Pandas group-by and sum
- How do I get the row count of a Pandas DataFrame?
- Python pandas groupby aggregate on multiple columns, then pivot
- Python Pandas Counting the Occurrences of a Specific value
- Convert pandas dataframe to NumPy array
- Count unique values per groups with Pandas
- Convert pandas Series to DataFrame
- Error:cannot convert float NaN to integer in pandas
- Replacing column values in a pandas DataFrame
- How do I get the row count of a Pandas DataFrame?
- Python Pandas – Missing required dependencies [‘numpy’] 1
- Pandas “Can only compare identically-labeled DataFrame objects” error
- Pandas: ValueError: cannot convert float NaN to integer
- Get list from pandas dataframe column or row?
- pandas DataFrame “no numeric data to plot” error
- ‘DataFrame’ object has no attribute ‘sort’
- TypeError: cannot unpack non-iterable int objec
- Pandas DataFrame column to list
- Rename Pandas DataFrame Index
- pandas: filter rows of DataFrame with operator chaining
- Convert DataFrame column type from string to datetime, dd/mm/yyyy format
- Pandas how to use pd.cut()
- How to Read .txt in Pandas
- Get a list from Pandas DataFrame column headers
- How to check whether a pandas DataFrame is empty?
- Convert columns to string in Pandas
- Python TypeError: cannot convert the series to
when trying to do math on dataframe - Shuffle DataFrame rows
- How to load a tsv file into a Pandas DataFrame?
- How to iterate over columns of pandas dataframe to run regression
- JSON to pandas DataFrame
- Converting between datetime and Pandas Timestamp objects
- Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
- Convert pandas data frame to series
- Create a Pandas Dataframe by appending one row at a time
- Modify the legend of pandas bar plot
- Get first row value of a given column
- Selecting/excluding sets of columns in pandas
- How to add title to seaborn boxplot
- Deleting DataFrame row in Pandas based on column value
- Map to List error: Series object not callable
- Pandas long to wide reshape, by two variables
- Pandas DataFrame: replace all values in a column, based on condition
- How to convert string to datetime format in pandas python?
- No numeric types to aggregate – change in groupby() behaviour?
- Data type conversion error: ValueError: Cannot convert non-finite values (NA or inf) to integer
- Pandas – How to flatten a hierarchical index in columns
- Pandas OR statement ending in series contains
- Plot correlation matrix using pandas
- How to get a value from a cell of a dataframe?
- Pandas split DataFrame by column value
- Plotting multiple lines, in different colors, with pandas dataframe
- Groupby value counts on the dataframe pandas
- TypeError: cannot concatenate a non-NDFrame object
- Pandas – Drop function error (label not contained in axis)
- Pandas index column title or name
- ImportError: No module named ‘xlrd’
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- Moving Average Pandas
- import pandas_datareader gives ImportError: cannot import name ‘is_list_like’
- How to add pandas data to an existing csv file?
- Importing Pandas gives error AttributeError: module ‘pandas’ has no attribute ‘core’ in iPython Notebook
- if else function in pandas dataframe
- matplotlib: plot multiple columns of pandas data frame on the bar chart
- Concat DataFrame Reindexing only valid with uniquely valued Index objects
- cannot convert the series to
- Read data (.dat file) with Pandas
- How to convert index of a pandas dataframe into a column
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- pandas replace multiple values one column
- Convert floats to ints in Pandas?
- pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
- Got continuous is not supported error in RandomForestRegressor
- Extract first and last row of a dataframe in pandas
- ValueError: Must pass DataFrame with boolean values only
- Error in Reading a csv file in pandas[CParserError: Error tokenizing data. C error: Buffer overflow caught – possible malformed input file.]
- Extracting specific selected columns to new DataFrame as a copy
- Compare two columns using pandas