I want to add columns from a list.
newcols = ['D', 'E', 'F']
df1 = (How it is)
A | B | C |
---|---|---|
10 | 15 | 5 |
11 | 14 | 9 |
df2 = (How i want it to be)
A | B | C | D | E | F |
---|---|---|---|---|---|
10 | 15 | 5 | |||
11 | 14 | 9 |
Do you guys know how to get this done ?? Best Regards!
I want to add columns from a list.
newcols = ['D', 'E', 'F']
df1 = (How it is)
A | B | C |
---|---|---|
10 | 15 | 5 |
11 | 14 | 9 |
df2 = (How i want it to be)
A | B | C | D | E | F |
---|---|---|---|---|---|
10 | 15 | 5 | |||
11 | 14 | 9 |
Do you guys know how to get this done ?? Best Regards!
Use concat
:
pd.concat([df, pd.DataFrame(columns=newcols)], axis=1)
assign directly
df[newcols] = ""