【问题标题】:Is it possible to plot a chart in python where both the x axis and y axis are categorical?是否可以在 python 中绘制 x 轴和 y 轴都是分类的图表?
【发布时间】:2021-05-09 19:51:29
【问题描述】:

我想用这个数据框制作一个气泡图,显示数据分析中缺失值的差距或频率。

是否可以在 x 轴上列出字段名称或分类值,并在 y 轴上绘制不同位置的缺失数量?

或者我需要为每个位置创建子图吗?

                 |Targeted Start Date  |Targeted End Date  |Projected End Date  
Location         | ------------------- | ----------------- | -----------------                    
Q                |                  0  |                0  |                 0   
R                |                  6  |                7  |               113   
V                |                  1  |                1  |                 6   
Z                |                  0  |                0  |                 0  

【问题讨论】:

    标签: python plot data-visualization categorical-data


    【解决方案1】:
    import altair as alt
    import pandas as pd
    import numpy as np
    d1 = {'Location': ['Q', 'R', 'V', 'Z'], 'Targeted Start Date': [0, 6, 1 ,0], 'Targeted End Date': [0, 7, 1 ,0], 'Targeted End Date': [0, 113, 6 ,0]}
    
    df = pd.DataFrame.from_dict(d1)
    
    #df = df.set_index('Location')
    
    print(df)
    
    dfMelt = df.melt(id_vars='Location', value_name='MissingItemCnt', var_name='FieldName')
    
    print(dfMelt)
    
    alt.Chart(dfMelt).mark_point().encode(x = 'FieldName', y = 'Location', size = 'MissingItemCnt')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多