How to specify default value when constructing Pandas Dataframe from two series (index and columns)?
I'm trying to construct a boolean 2D array set to initial value of False. The following code sets it to True by default:
import pandas as pd
from datetime import date
date_start = date(2022, 1, 1)
date_end = date(2022, 8, 24)
valid_dates = pd.bdate_range(date_start, date_end)
cols = range(0,4)
df = pd.DataFrame(index=valid_dates, columns=cols, dtype='bool')
I know I can do the following to replace the values to False, but it takes significantly longer:
df = df.replace(df, False)
My actual columns is much larger e.g. ~500 columns. Is there a way to just initialize the dataframe to be False?
source https://stackoverflow.com/questions/73478915/how-to-specify-default-value-when-constructing-pandas-dataframe-from-two-series
Comments
Post a Comment