Complete error reports are as follows: pandas core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).
Solution:
There are two indexing methods, one of which can be selected:
Solution 1
dataframe[pd.Series([True, True, True], index=dataframe.index)]
Solution 2:
dataframe.loc[pd.Series([True, True], index=['a', 'b']).index]
Problem analysis
An error will appear in the following code:
import pandas as pd
import numpy as np
dataframe = pd.DataFrame(data=np.random.random(size=(3, 5)), index=['a', 'b', 'c'])
Error codes are as follows:
dataframe[pd.Series([True, True], index=['a', 'b'])]
You can see that the original dataframe
includes 3 lines, but there are only two true values here, so an error is reported. The correct method is:
dataframe[pd.Series([True, True, True], index=['a', 'b', 'c'])]
dataframe.loc[pd.Series([True, True], index=['a', 'b']).index]
Read More:
- Panda error in modifying line name index does not support mutable operations
- Python: Panda scramble data
- [How to Fix]The truth value of a series is ambiguous
- Pandas ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.an
- Python errors: valueerror: if using all scalar values, you must pass an index (four solutions)
- [Solved] python Error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.
- Mxnet Export onnx Symbol and params files provided are invalid
- Python Valueerror: cannot index with vector containing Na / Nan values
- [resolution] str.contains() problem] valueerror: cannot index with vector containing Na/Nan values
- [Solved] RuntimeError: scatter(): Expected dtype int64 for index
- IndexError: list index out of range [How to Solve]
- [Solved] ValueError: row index was 65536, not allowed by .xls format
- [Solved] yolo Error: IndexError: invalid index to scalar variable.
- Django PythonConsole error: Requested setting DEFAULT_INDEX_TABLESPACE
- import matplotlib.pyplot as plt [How to Solve]
- [Solved] RuntimeError: gather(): Expected dtype int64 for index
- [Solved] Python Networkx Error: Network error: random_state_index is incorrect
- import statsmodels.api as sm Error: ImportError: DLL load failed while importing _arpack: The specified program could not be found.
- ācā argument looks like a single numeric RGB or RGBA sequence, which should be avoided as value-mapp
- Xpath Error: IndexError: list index out of range [How to Solve]