简体   繁体   中英

How to set pandas columns names from a dictionary of lists?

I have a dict like:

actions = {0: [0, 1, 2, 4], 
           1: [0, 1, 8, 5, 2, 4], 
           2: [0, 1, 2, 5, 6]}

And I would like to create a dataframe where the column names where:

state_actions = pd.Dataframe()
  
Empty DataFrame
Columns: [[0, 1, 2, 4], [0, 1, 8, 5, 2, 4], [0, 1, 2, 5, 6]]
Index: []
 

The idea is to have as column names the dict values.

pd.DataFrame(columns=actions.values())
Empty DataFrame
Columns: [[0, 1, 2, 4], [0, 1, 8, 5, 2, 4], [0, 1, 2, 5, 6]]
Index: []

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM