简体   繁体   English

如何将这本字典在一列中拆分为他们自己的列?

[英]How can I split this dictionary in a column in to their own columns?

How can I make this dictionary in a column into its own columns?我怎样才能使这个字典在一列中变成它自己的列? With the Keys being the column name and the value being the data键是列名,值是数据

This is the dictionary, would like to have keys as the column title and values the data:这是字典,希望将键作为列标题并为数据赋值: 图片

Try the following:尝试以下操作:

import pandas as pd
dct = {'key1': 'a', 'key2': 'b', 'key3': 'c'}
df = pd.DataFrame(data=[list(dct.values())], columns=list(dct.keys()))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当使用 PySpark 在列中以逗号分隔时,如何将列拆分为它们自己的行? - How can I split columns to their own row when comma-separated in column using PySpark? 如何将一列拆分为多列? - How can i split a column into multiple columns? 如何将此包含字典的列表拆分为单独的列? - How can I split out this list containing a dictionary into separate columns? 列存储为列表; 如何在 pandas python 中拆分为 COLUMNS? - Column stored as List; how can I split as COLUMNS in pandas python? 如何在 Pandas 中将特定列拆分为新列? - How can I split a specific column to new columns in Pandas? 如何在 pandas 中将一列不按顺序的项目拆分为它们自己的列? - How to split a column of items - which are not in order, into their own columns in pandas? 如何将具有值作为字典的列拆分为新列(具有 NaN 值) - How to split a column with values as dictionary to new columns (with NaN values) 如何将一列中的字典列表拆分为 pyspark dataframe 中的两列? - How to split list of dictionary in one column into two columns in pyspark dataframe? 如何用逗号分割字典的值? - How can I split values of a dictionary by comma? 如何将具有3列的csv转换为以1列为键,1列为其值的字典并获取键的值 - How can I convert a csv with 3 columns to a dictionary with 1 column as key, 1 column as its value and fetch the value for key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM