Katty_one
Katty_one

Reputation: 351

Columns names of a dataframe from a list of names

I have a list of names:

list_names = ['Albert','Marcos','Alberta']

and I have an empty dataframe:

t=pd.DataFrame()

How can I add list_names as columns in the dataframe t with values = 10, like this:

Albert  Marcos   Alberta
 10      10        10

Upvotes: 0

Views: 21

Answers (2)

wwnde
wwnde

Reputation: 26676

Use reindex to create columns and loc to append data

t =t.reindex(list_names, axis='columns')
t.loc[0]=10

Upvotes: 1

nathan liang
nathan liang

Reputation: 1383

t = pd.DataFrame({'Albert': 10, 'Marcos': 10, 'Alberta': 10})

Upvotes: 0

Related Questions