python - Pandas: Add multiple empty columns to DataFrame -
this may stupid question, how add multiple empty columns dataframe list?
i can do:
df["b"] = none df["c"] = none df["d"] = none
but can't do:
df[["b", "c", "d"]] = none keyerror: "['b' 'c' 'd'] not in index"
i'd concat
using dataframe ctor:
in [23]: df = pd.dataframe(columns=['a']) df out[23]: empty dataframe columns: [a] index: [] in [24]: pd.concat([df,pd.dataframe(columns=list('bcd'))]) out[24]: empty dataframe columns: [a, b, c, d] index: []
so passing list containing original df, , new 1 columns wish add, return new df additional columns.
Comments
Post a Comment