-
Notifications
You must be signed in to change notification settings - Fork 0
/
company_count.py
59 lines (52 loc) · 1.91 KB
/
company_count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Author: You Sen Wang (Ethan)
Started Date: 04/06/2020
Email: [email protected]
Please read the README.md before using it.
"""
#%%
import pandas as pd
import numpy as np
from collections import Counter, OrderedDict
#%%
#source = './104人力銀行SAP.csv'
source = './104人力銀行_SAP_positions_utf8.csv'
pd_data = pd.read_csv(source, encoding = 'utf-8')
n = pd_data.shape[0]
counter = Counter(pd_data["公司名稱"])
sorted_counter = sorted(counter.items(),key=lambda i:i[1], reverse=True)
n_threshold = -1
companies = [k[0] for k in sorted_counter if k[1] > n_threshold]
companies_count = [k[1] for k in sorted_counter if k[1] > n_threshold]
col_names = ["name", "count"]
dat = np.transpose(np.array([companies, companies_count]))
df = pd.DataFrame(dat, columns=col_names)
print(df.head(5))
import datetime
time_produced = datetime.datetime.now().strftime("%d_%m_%Y_%H_%M_%S")
path = f'./companies_name_and_count_{time_produced}.csv'
try:
df.to_csv(path, encoding='big5', index=False)
except UnicodeEncodeError:
pass
print(path)
n_threshold = 4
companies = [k[0] for k in sorted_counter if k[1] > n_threshold]
companies_count = [k[1] for k in sorted_counter if k[1] > n_threshold]
top_n = len(companies_count)
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei']
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(19.2 * 1, 10.8 / 1.3 * 4))
#plt.yscale('log', nonposy='clip')
#plt.tight_layout()
plt.xticks(range(len(companies_count)), companies, rotation='vertical')
plt.bar(range(len(companies_count)), companies_count, align='center')
plt.ylim(bottom=min(companies_count))
plt.title(f'Companies that hire SAP positions. \n Sample size(n): {n}, Top n: {top_n}')
plt.ylabel('position count')
plt.xlabel('companies name')
pic_name = f'SAP_company_list_{time_produced}.jpg'
plt.savefig(pic_name)
print(f"{pic_name} was produced.")