[英](Row, Column) : Value to Pandas DataFrame
I have a DataSet in the Following Format coming from a rester Service我有一个来自恢复服务的以下格式的数据集
{'C': {('x', 'Active'): 1, ('x', 'Ready'): 1, ('y', 'Active'): 1, ('y', 'Ready'): 1, ('z', 'Active'): 1, ('z', 'Ready'): 2}}
and the Excepted Out I Want is而我想要的例外是
But when i try to load data in DF it Loads the Key ie (Row,Column) as Index但是当我尝试在 DF 中加载数据时,它会加载键,即(行,列)作为索引
You can do:你可以做:
pd.Series(data['C']).unstack()
Output: Output:
Active Ready
x 1 1
y 1 1
z 1 2
Another way;另一种方式; Apply pd.DataFrame and drop multiindex columns
应用 pd.DataFrame 并删除多索引列
df=pd.DataFrame(data).unstack()
df.columns=df.columns.droplevel()
Active Ready
x 1 1
y 1 1
z 1 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.