123456789101112131415161718192021 |
- import matplotlib.pyplot as plt
- import seaborn as sns
- import squarify
- import pandas as pd
- rawdata = pd.read_csv('../docs/keyword.csv')
- # rawdata = sns.load_dataset(df)
- # print(rawdata.head())
- # n = rawdata.groupby('Competition')[['Avg. monthly searches']].sum()
- # print(n)
- a = rawdata.groupby('Keyword')[['Avg_monthly_searches']].sum().index.get_level_values(0).tolist()#取得index裡的[0]再轉為list
- print(a)
- d = rawdata.groupby('Keyword')[['Avg_monthly_searches']].sum().reset_index().Avg_monthly_searches.values.tolist()#This gives us the labels in the form of a list. To get the values corresponding to these labels, use :
- print(d)
- plt.rcParams['font.sans-serif'] = ['Taipei Sans TC Beta']
- squarify.plot(sizes=d, label=a, alpha=.8)
- plt.axis('off')
- plt.show()
|