[英]add two dictionaries that are already inside a dictionary in each row of datframe
I have dictionary that has two dictionaries inside it in each row of a column.我有一个字典,每一列的每一行都有两个字典。 Column name is 'price' and I have written two rows here:列名是“价格”,我在这里写了两行:
row1 = {'offer_price': {'currency': 'GBP', 'value': 35.0}, 'regular_price': {'currency': 'GBP', 'value': 35.0}}
row2 = {'offer_price': {'currency': 'GBP', 'value': 55.0}, 'regular_price': {'currency': 'GBP', 'value': 55.0}}
I need to create a dataframe that has three columns, namely 'offer_price', 'regular_price' and 'currency', with the 'value' in both price columns and GBP in currency column.我需要创建一个包含三列的数据框,即“offer_price”、“regular_price”和“currency”,价格列中为“value”,货币列中为 GBP。
I have tried but I am not getting the required dataframe我试过了,但我没有得到所需的数据框
df1 = pd.DataFrame()
for rows in df.price:
x = pd.DataFrame(rows)
df1 = df1.append(x)
You could use this command你可以使用这个命令
pd.DataFrame.from_dict(row1)
It will permits you to create Dataframe from dict.它将允许您从 dict 创建 Dataframe。
You can find documentation here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_dict.html您可以在此处找到文档: https : //pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_dict.html
I hope it will helps you !我希望它会帮助你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.