是否可以在 python 中绘制图表,其中 x 轴和 y 轴都是分类的?
Is it possible to plot a chart in python where both the x axis and y axis are categorical?
我想用这个数据框制作一个气泡图,显示数据分析中缺失值的差距或频率。
是否可以在 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
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')
我想用这个数据框制作一个气泡图,显示数据分析中缺失值的差距或频率。
是否可以在 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
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')