Python - 在图表中可视化数据
Python - Visualizing data in a diagram
我有一个包含两列的数据:产品和类别。请参阅下面的数据示例:
import pandas as pd
df = pd.DataFrame({'Product': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'],
'Category': ['Text', 'Text2', 'Text3', 'Text4', 'Text', 'Text2', 'Text3', 'Text4'],
'Value': [80, 10, 5, 5, 5, 3, 2, 0]})
我想在图表中可视化此数据:
这里的"Total"是整个数据框的总值,"A"&"B"框是每个产品的总值,然后是每个产品的值&类别位于最右侧的框中。
我对 Python 中可用的可视化包不是很熟悉。是否存在执行这些类型的可视化的软件包。
您可以使用 graphviz。但是你需要自己提取blocks/nodes
示例:
from graphviz import Graph
g = Graph()
g.attr(rankdir='RL')
T = df['Value'].sum()
g.node('1', 'Total = ' + str(T), shape='square')
A = df.loc[df.Product == 'A', ['Category', 'Value']].to_string(index=False)
g.node('2', A, shape='square')
B = df.loc[df.Product == 'B', ['Category', 'Value']].to_string(index=False)
g.node('3', B, shape='square')
g.edges(['21', '31'])
g.render(view=True)
我有一个包含两列的数据:产品和类别。请参阅下面的数据示例:
import pandas as pd
df = pd.DataFrame({'Product': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'],
'Category': ['Text', 'Text2', 'Text3', 'Text4', 'Text', 'Text2', 'Text3', 'Text4'],
'Value': [80, 10, 5, 5, 5, 3, 2, 0]})
我想在图表中可视化此数据:
这里的"Total"是整个数据框的总值,"A"&"B"框是每个产品的总值,然后是每个产品的值&类别位于最右侧的框中。
我对 Python 中可用的可视化包不是很熟悉。是否存在执行这些类型的可视化的软件包。
您可以使用 graphviz。但是你需要自己提取blocks/nodes
示例:
from graphviz import Graph
g = Graph()
g.attr(rankdir='RL')
T = df['Value'].sum()
g.node('1', 'Total = ' + str(T), shape='square')
A = df.loc[df.Product == 'A', ['Category', 'Value']].to_string(index=False)
g.node('2', A, shape='square')
B = df.loc[df.Product == 'B', ['Category', 'Value']].to_string(index=False)
g.node('3', B, shape='square')
g.edges(['21', '31'])
g.render(view=True)