我在一列中有数据,如何提取呢?
例如: Shape_attribute是列名 {“名称”:“圆”,“ cx”:371,“ cy”:2921,“ r”:73} {“名称”:“圆”,“ cx”:3712,“ cy”:29212,“ r”:73} {“ name”:“ circle”,“ cx”:371,“ cy”:2921,“ r”:73}
我想要输出如下:
name cx cy r
circle 371 2921 73
circle 3712 29212 73
circle 371 2921 73
注意:所有4个值都在同一列shape_attributes
答案 0 :(得分:2)
这有效:
df_final = pd.concat([df, df['shape_attributes'].apply(pd.Series)], axis = 1).drop('shape_attributes', axis = 1)
答案 1 :(得分:1)
首先创建一个值字典,然后将其传递给Pandas Dataframe,如下所示:
import pandas as pd
my_dict={"name":"circle","cx":371,"cy":2921,"r":73}
df=pd.DataFrame([my_dict],columns=my_dict.keys())
还要了解有关将字典转换为数据帧的更多信息,请访问此Dictionary to DataFrame
答案 2 :(得分:0)
Python 3.x
REGULAR_ID SPECIAL_ID
3 NULL
或:
dict = {"name":"circle","cx":371,"cy":2921,"r":73}
keys= []
values = []
for key, value in dict.items():
keys.append(str(key))
values.append(str(value))
data = [keys, values]
for row in data: # Align right
print("{: >10} {: >10} {: >10} {: >10}".format(*row))
for row in data: # Align left
print("{: <10} {: <10} {: <10} {: <10}".format(*row))
答案 3 :(得分:0)
从字典中生成系列,转换为DataFrame,然后转置:
d = {"name":"circle","cx":371,"cy":2921,"r":73}
pd.Series(d).to_frame().T
输出:
name cx cy r
0 circle 371 2921 73
答案 4 :(得分:0)
您可以将pd.Series应用于包含词典的列:
result = df['target_column'].apply(pd.Series)