Create a DataFrame birds from this dictionary data which has the index labels

前端 未结 4 1765
旧巷少年郎
旧巷少年郎 2021-01-24 08:13

Consider the following Python dictionary data and Python list labels:**

data = {\'birds\': [\'Cranes\', \'Cranes\', \'plovers\', \'spoonbills\', \'spoonbills\',          


        
4条回答
  •  爱一瞬间的悲伤
    2021-01-24 08:53

    You can reduce some code like:

    DataFrame provides us a flexibilty to provide some values like data,columns,index and the list goes on.

    If we are dealing with Dictionary, then by default dictionaries keys are treated as column and values will be as rows.

    In following Code I have used name attribute through DataFrame object

    df=pd.DataFrame(data,index=Labels) # Custom indexes
    df.index.name='labels'             # After Running df.index.name you will get index as none, by this approach you can set any name to the column
    

    I hope this will be help full for you.

提交回复
热议问题