A succinct way to convert a single column of boolean values to a column of integers 1 or 0:
df["somecolumn"] = df["somecolumn"].astype(int)
More Related Contents:
- Filtering pandas dataframe with multiple Boolean columns
- Pandas conditional creation of a series/dataframe column
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Split (explode) pandas dataframe string entry to separate rows
- Logical operators for Boolean indexing in Pandas
- Convert pandas dataframe to NumPy array
- Binning a column with Python Pandas
- Performant cartesian product (CROSS JOIN) with pandas
- Pandas read_csv low_memory and dtype options
- How to take column-slices of dataframe in pandas
- What does axis in pandas mean?
- replace() method not working on Pandas DataFrame
- Numpy “where” with multiple conditions
- How to map numeric data into categories / bins in Pandas dataframe
- Conditionally fill column values based on another columns value in pandas
- How to check if a value is in the list in selection from pandas data frame?
- Pandas finding local max and min
- SQL-like window functions in PANDAS: Row Numbering in Python Pandas Dataframe
- Pandas lookup from one of multiple columns, based on value
- ‘DataFrame’ object has no attribute ‘sort’
- python pandas flatten a dataframe to a list
- how do I calculate a rolling idxmax
- What is dtype(‘O’), in pandas?
- vectorize conditional assignment in pandas dataframe
- Why is np.where faster than pd.apply
- Binning a column with pandas
- Unpivot Pandas Data
- Get first and second highest values in pandas columns
- Store numpy.array in cells of a Pandas.DataFrame
- Python pandas: how to remove nan and -inf values