SHARE
TWEET

Untitled

jjjj88521 Nov 19th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import matplotlib.pyplot as plt
  2. import csv  
  3. import pandas as pd
  4.  
  5. from matplotlib.font_manager import FontProperties
  6. import matplotlib.pyplot as plt
  7. plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei']
  8. plt.rcParams['axes.unicode_minus'] = False
  9.  
  10. filename='t187ap05_L.csv'
  11.  
  12. industry_dic = {}
  13.  
  14. revenue_dic = {}
  15. with open(filename,"r",encoding="utf-8") as file:
  16.    
  17.    # cols4 = sheet1.col_values(4)
  18.    
  19.     reader = csv.reader(file)
  20.     header_col=next(reader)
  21.     for col in reader:
  22.         if col[4] in industry_dic.keys():
  23.             industry_dic[col[4]] += 1
  24.         else:
  25.             industry_dic[col[4]] = 1
  26.            
  27.  
  28.         if col[4] in revenue_dic.keys():
  29.             revenue_dic[col[4]] += int(col[5])
  30.         else:
  31.             revenue_dic[col[4]] = 0
  32.            
  33.  
  34.  
  35. #各產業公司數長條圖
  36. label = list(industry_dic.keys())
  37. quantity = list(industry_dic.values())
  38. index = list(range(len(label)))
  39. plt.figure(figsize=(10,10))
  40. plt.barh(label,quantity)
  41. plt.yticks(index,label)
  42. plt.xlabel('公司數')
  43. plt.title('各產業公司數')
  44. plt.show()
  45.  
  46. #各產業當月營收圓餅圖
  47. label = list(revenue_dic.keys())
  48. revenue = list(revenue_dic.values())
  49. plt.figure(figsize=(15,15))
  50. plt.pie(revenue, labels = label, autopct = "%1.1f%%",
  51.         textprops = {"fontsize" : 8},labeldistance = 1.02)
  52. plt.title('各產業當月營收百分比',fontsize = 10)
  53. plt.axis("off")
  54. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top