import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
% matplotlib inline
df_2007 = pd.read_csv('./data/data_forbes_2007.csv', encoding='gbk', thousands=',')
print('the shape of DataFrame: ', df_2007.shape)
print(df_2007.dtypes)
df_2007.head(3)
the shape of DataFrame: (2000, 9) 年份 int64 排名(Rank) int64 公司名称(Company) object 所在国家或地区(Country) object 所在行业(Industry) object 销售收入(Sales) object 利润(Profits) object 总资产(Assets) object 市值(Market Vaue) float64 dtype: object
年份 | 排名(Rank) | 公司名称(Company) | 所在国家或地区(Country) | 所在行业(Industry) | 销售收入(Sales) | 利润(Profits) | 总资产(Assets) | 市值(Market Vaue) | |
---|---|---|---|---|---|---|---|---|---|
0 | 2007 | 1 | Citigroup /花旗集团 | 美国(US) | 银行 | 146.56 | 21.54 | 1,884.32 | 247.42 |
1 | 2007 | 2 | Bank of America /美国银行 | 美国(US) | 银行 | 116.57 | 21.13 | 1,459.74 | 226.61 |
2 | 2007 | 3 | HSBC Holdings/汇丰集团 | 英国(UK) | 银行 | 121.51 | 16.63 | 1,860.76 | 202.29 |
column_update = ['Year', 'Rank', 'Company_cn_en', 'Country_cn_en',
'Industry_cn', 'Sales', 'Profits', 'Assets', 'Market_value']
df_2007.columns = column_update
df_2007.head(3)
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
0 | 2007 | 1 | Citigroup /花旗集团 | 美国(US) | 银行 | 146.56 | 21.54 | 1,884.32 | 247.42 |
1 | 2007 | 2 | Bank of America /美国银行 | 美国(US) | 银行 | 116.57 | 21.13 | 1,459.74 | 226.61 |
2 | 2007 | 3 | HSBC Holdings/汇丰集团 | 英国(UK) | 银行 | 121.51 | 16.63 | 1,860.76 | 202.29 |
df_2007[df_2007['Sales'].str.contains('.*[A-Za-z]', regex=True)]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
117 | 2007 | 118 | Repsol-YPF /瑞普索 | 西班牙(SP) | 炼油 | 64.20 E | 4.12 | 58.43 | 38.75 |
616 | 2007 | 617 | Inpex Holdings | 日本(JA) | 炼油 | 6.49 E | 1.02 E | 10.77 E | 19.65 |
880 | 2007 | 881 | Asahi Breweries/朝日啤酒 | 日本(JA) | 食品、饮料和烟草 | 7.97 E | 0.38 | 10.66 | 7.71 |
df_2007['Sales'] = df_2007['Sales'].replace('([A-Za-z])', '', regex=True)
df_2007.loc[[117,616,880], :]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
117 | 2007 | 118 | Repsol-YPF /瑞普索 | 西班牙(SP) | 炼油 | 64.20 | 4.12 | 58.43 | 38.75 |
616 | 2007 | 617 | Inpex Holdings | 日本(JA) | 炼油 | 6.49 | 1.02 E | 10.77 E | 19.65 |
880 | 2007 | 881 | Asahi Breweries/朝日啤酒 | 日本(JA) | 食品、饮料和烟草 | 7.97 | 0.38 | 10.66 | 7.71 |
df_2007[df_2007['Assets'].str.contains('.*[A-Za-z]', regex=True)]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
616 | 2007 | 617 | Inpex Holdings | 日本(JA) | 炼油 | 6.49 | 1.02 E | 10.77 E | 19.65 |
# 将数字后面的字母进行替换
df_2007['Assets'] = df_2007['Assets'].replace('([A-Za-z])', '', regex=True)
# 千分位数字的逗号被识别为string了,需要替换
df_2007['Assets'] = df_2007['Assets'].replace(',', '', regex=True)
df_2007.loc[616, :]
Year 2007 Rank 617 Company_cn_en Inpex Holdings Country_cn_en 日本(JA) Industry_cn 炼油 Sales 6.49 Profits 1.02 E Assets 10.77 Market_value 19.65 Name: 616, dtype: object
df_2007[pd.isnull(df_2007['Profits'])]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
958 | 2007 | 959 | UAL/美国联合航空公司 | 美国(US) | 运输 | 19.34 | NaN | 25.86 | 4.43 |
1440 | 2007 | 1441 | Owens Corning/欧文斯科宁 | 美国(US) | 建筑 | 6.46 | NaN | 8.47 | 4.19 |
1544 | 2007 | 1545 | Parmalat/帕玛拉特公司 | 意大利(IT) | 食品、饮料和烟草 | 4.83 | NaN | 4.90 | 7.02 |
1912 | 2007 | 1912 | Winn-Dixie Stores | 美国(US) | 食品市场 | 6.96 | NaN | 1.62 | 1.05 |
df_2007['Profits'].fillna(0, inplace=True)
df_2007.loc[[958,1440,1544,1912], :]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
958 | 2007 | 959 | UAL/美国联合航空公司 | 美国(US) | 运输 | 19.34 | 0 | 25.86 | 4.43 |
1440 | 2007 | 1441 | Owens Corning/欧文斯科宁 | 美国(US) | 建筑 | 6.46 | 0 | 8.47 | 4.19 |
1544 | 2007 | 1545 | Parmalat/帕玛拉特公司 | 意大利(IT) | 食品、饮料和烟草 | 4.83 | 0 | 4.90 | 7.02 |
1912 | 2007 | 1912 | Winn-Dixie Stores | 美国(US) | 食品市场 | 6.96 | 0 | 1.62 | 1.05 |
df_2007['Profits'] = df_2007['Profits'].replace('([A-Za-z])', '', regex=True)
df_2007.loc[[117,616,880], :]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
117 | 2007 | 118 | Repsol-YPF /瑞普索 | 西班牙(SP) | 炼油 | 64.20 | 4.12 | 58.43 | 38.75 |
616 | 2007 | 617 | Inpex Holdings | 日本(JA) | 炼油 | 6.49 | 1.02 | 10.77 | 19.65 |
880 | 2007 | 881 | Asahi Breweries/朝日啤酒 | 日本(JA) | 食品、饮料和烟草 | 7.97 | 0.38 | 10.66 | 7.71 |
df_2007['Sales'] = pd.to_numeric(df_2007['Sales'])
df_2007['Profits'] = pd.to_numeric(df_2007['Profits'])
df_2007['Assets'] = pd.to_numeric(df_2007['Assets'])
df_2007.dtypes
Year int64 Rank int64 Company_cn_en object Country_cn_en object Industry_cn object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
df_2007['Company_en'],df_2007['Company_cn'] = df_2007['Company_cn_en'].str.split('/', 1).str
print(df_2007['Company_en'][:5])
print(df_2007['Company_cn'] [-5:])
0 Citigroup 1 Bank of America 2 HSBC Holdings 3 General Electric 4 JPMorgan Chase Name: Company_en, dtype: object 1995 NaN 1996 NaN 1997 NaN 1998 NaN 1999 NaN Name: Company_cn, dtype: object
df_2007.tail(3)
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | Company_en | Company_cn | |
---|---|---|---|---|---|---|---|---|---|---|---|
1997 | 2007 | 1998 | CBOT Holdings | 美国(US) | 综合金融 | 0.64 | 0.17 | 0.81 | 8.54 | CBOT Holdings | NaN |
1998 | 2007 | 1998 | Singapore Petroleum | 新加坡(SI) | 炼油 | 5.59 | 0.19 | 2.05 | 1.50 | Singapore Petroleum | NaN |
1999 | 2007 | 2000 | DVB Bank | 德国(GE) | 银行 | 0.77 | 0.06 | 12.74 | 1.26 | DVB Bank | NaN |
df_2007['Country_cn'],df_2007['Country_en'] = df_2007['Country_cn_en'].str.split('(', 1).str
print(df_2007['Country_cn'][:5])
print(df_2007['Country_en'][-5:])
0 美国 1 美国 2 英国 3 美国 4 美国 Name: Country_cn, dtype: object 1995 US) 1996 US) 1997 US) 1998 SI) 1999 GE) Name: Country_en, dtype: object
df_2007['Country_en'] = df_2007['Country_en'].str.slice(0,-1)
df_2007.head(3)
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | Company_en | Company_cn | Country_cn | Country_en | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2007 | 1 | Citigroup /花旗集团 | 美国(US) | 银行 | 146.56 | 21.54 | 1884.32 | 247.42 | Citigroup | 花旗集团 | 美国 | US |
1 | 2007 | 2 | Bank of America /美国银行 | 美国(US) | 银行 | 116.57 | 21.13 | 1459.74 | 226.61 | Bank of America | 美国银行 | 美国 | US |
2 | 2007 | 3 | HSBC Holdings/汇丰集团 | 英国(UK) | 银行 | 121.51 | 16.63 | 1860.76 | 202.29 | HSBC Holdings | 汇丰集团 | 英国 | UK |
df_2007[df_2007['Country_cn'].str.contains('中国',regex=True)]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | Company_en | Company_cn | Country_cn | Country_en | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
40 | 2007 | 41 | PetroChina /中国石油 | 中国大陆(CN) | 炼油 | 68.43 | 16.53 | 96.42 | 208.76 | PetroChina | 中国石油 | 中国大陆 | CN |
52 | 2007 | 53 | ICBC /中国工商银行 | 中国大陆(CN) | 银行 | 31.98 | 4.65 | 800.04 | 176.03 | ICBC | 中国工商银行 | 中国大陆 | CN |
68 | 2007 | 69 | CCB-China Construction Bank /中国建设银行 | 中国大陆(CN) | 银行 | 23.18 | 5.84 | 568.21 | 126.55 | CCB-China Construction Bank | 中国建设银行 | 中国大陆 | CN |
70 | 2007 | 71 | Sinopec-China Petroleum /中石化 | 中国大陆(CN) | 炼油 | 99.03 | 5.07 | 65.83 | 93.57 | Sinopec-China Petroleum | 中石化 | 中国大陆 | CN |
81 | 2007 | 82 | Bank of China /中国银行 | 中国大陆(CN) | 银行 | 23.10 | 3.41 | 585.55 | 143.80 | Bank of China | 中国银行 | 中国大陆 | CN |
88 | 2007 | 89 | China Mobile /中国移动 | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 29.79 | 6.56 | 51.35 | 185.31 | China Mobile | 中国移动 | 中国香港 | HK)/中国大陆(CN |
175 | 2007 | 176 | Hutchison Whampoa/和记黄埔 | 中国香港(HK)/中国大陆(CN) | 多元化 | 23.55 | 1.85 | 74.97 | 40.57 | Hutchison Whampoa | 和记黄埔 | 中国香港 | HK)/中国大陆(CN |
180 | 2007 | 181 | China Telecom/中国电信 | 中国大陆(CN) | 电信运营商 | 20.98 | 3.46 | 50.34 | 37.50 | China Telecom | 中国电信 | 中国大陆 | CN |
242 | 2007 | 243 | China Life Insurance /中国人寿 | 中国大陆(CN) | 保险 | 11.18 | 1.15 | 69.30 | 109.96 | China Life Insurance | 中国人寿 | 中国大陆 | CN |
307 | 2007 | 308 | Bank of Communications/中国交通银行 | 中国大陆(CN) | 银行 | 6.64 | 1.15 | 176.27 | 46.14 | Bank of Communications | 中国交通银行 | 中国大陆 | CN |
309 | 2007 | 310 | Taiwan Semiconductor/台积电 | 中国台湾(TA) | 半导体 | 9.74 | 3.90 | 18.02 | 54.32 | Taiwan Semiconductor | 台积电 | 中国台湾 | TA |
340 | 2007 | 341 | Hon Hai Precision Ind /鸿海精密 | 中国台湾(TA) | 技术硬件和装备 | 27.78 | 1.24 | 13.99 | 34.83 | Hon Hai Precision Ind | 鸿海精密 | 中国台湾 | TA |
365 | 2007 | 366 | Baoshan Iron & Steel /上海宝钢集团 | 中国大陆(CN) | 材料 | 15.63 | 1.57 | 17.59 | 21.42 | Baoshan Iron & Steel | 上海宝钢集团 | 中国大陆 | CN |
388 | 2007 | 389 | Cathay Financial/国泰金融 | 中国台湾(TA) | 保险 | 10.09 | 0.66 | 93.29 | 19.87 | Cathay Financial | 国泰金融 | 中国台湾 | TA |
394 | 2007 | 395 | Cnooc /中海油 | 中国香港(HK)/中国大陆(CN) | 炼油 | 8.51 | 3.10 | 14.22 | 34.94 | Cnooc | 中海油 | 中国香港 | HK)/中国大陆(CN |
400 | 2007 | 401 | China Netcom Group /中国网通 | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 10.69 | 1.70 | 24.70 | 15.70 | China Netcom Group | 中国网通 | 中国香港 | HK)/中国大陆(CN |
422 | 2007 | 423 | China Shenhua Energy/中国神华能源股份有限公司 | 中国大陆(CN) | 材料 | 6.47 | 1.94 | 17.08 | 45.94 | China Shenhua Energy | 中国神华能源股份有限公司 | 中国大陆 | CN |
429 | 2007 | 430 | BOC Hong Kong/中银香港 | 中国香港(HK)/中国大陆(CN) | 银行 | 4.13 | 1.74 | 106.03 | 25.58 | BOC Hong Kong | 中银香港 | 中国香港 | HK)/中国大陆(CN |
436 | 2007 | 437 | Formosa Petrochemical/台塑石化 | 中国台湾(TA) | 炼油 | 13.56 | 1.74 | 12.35 | 19.28 | Formosa Petrochemical | 台塑石化 | 中国台湾 | TA |
439 | 2007 | 440 | Ping An Insurance Group/平安保险 | 中国大陆(CN) | 保险 | 7.95 | 0.52 | 39.62 | 39.60 | Ping An Insurance Group | 平安保险 | 中国大陆 | CN |
451 | 2007 | 452 | Jardine Matheson/香港怡和集团 | 中国香港(HK)/中国大陆(CN) | 食品市场 | 11.96 | 1.25 | 18.34 | 13.59 | Jardine Matheson | 香港怡和集团 | 中国香港 | HK)/中国大陆(CN |
510 | 2007 | 511 | Sun Hung Kai Properties /新鸿基房地产 | 中国香港(HK)/中国大陆(CN) | 综合金融 | 3.30 | 2.56 | 29.72 | 29.49 | Sun Hung Kai Properties | 新鸿基房地产 | 中国香港 | HK)/中国大陆(CN |
541 | 2007 | 542 | China Unicom /中国联通 | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 10.67 | 0.60 | 17.63 | 16.03 | China Unicom | 中国联通 | 中国香港 | HK)/中国大陆(CN |
551 | 2007 | 552 | CLP Holdings /中电控股 | 中国香港(HK)/中国大陆(CN) | 公用事业 | 5.87 | 1.27 | 16.42 | 17.65 | CLP Holdings | 中电控股 | 中国香港 | HK)/中国大陆(CN |
575 | 2007 | 576 | Chunghwa Telecom/中华电信 | 中国台湾(TA) | 电信运营商 | 5.59 | 1.45 | 13.98 | 18.22 | Chunghwa Telecom | 中华电信 | 中国台湾 | TA |
600 | 2007 | 601 | China Steel/台湾中钢公司 | 中国台湾(TA) | 材料 | 8.66 | 1.54 | 10.35 | 12.24 | China Steel | 台湾中钢公司 | 中国台湾 | TA |
603 | 2007 | 604 | China Merchants Bank/招商银行 | 中国大陆(CN) | 银行 | 3.53 | 0.46 | 90.76 | 33.19 | China Merchants Bank | 招商银行 | 中国大陆 | CN |
617 | 2007 | 617 | Nan Ya Plastic/南亚塑胶工业 | 中国台湾(TA) | 化学制品 | 7.64 | 1.22 | 11.47 | 13.37 | Nan Ya Plastic | 南亚塑胶工业 | 中国台湾 | TA |
627 | 2007 | 628 | Cheung Kong/长江集团 | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.80 | 1.80 | 28.01 | 28.39 | Cheung Kong | 长江集团 | 中国香港 | HK)/中国大陆(CN |
736 | 2007 | 737 | Swire Pacific /太古集团 | 中国香港(HK)/中国大陆(CN) | 多元化 | 2.44 | 2.42 | 16.05 | 17.32 | Swire Pacific | 太古集团 | 中国香港 | HK)/中国大陆(CN |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
1636 | 2007 | 1637 | Champion REIT | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.05 | 1.16 | 2.95 | 1.54 | Champion REIT | NaN | 中国香港 | HK)/中国大陆(CN |
1641 | 2007 | 1642 | Noble Group | 中国香港(HK)/中国大陆(CN) | 运输 | 13.75 | 0.13 | 3.81 | 2.14 | Noble Group | NaN | 中国香港 | HK)/中国大陆(CN |
1661 | 2007 | 1662 | Taiwan Mobile | 中国台湾(TA) | 电信运营商 | 1.81 | 0.50 | 3.59 | 4.84 | Taiwan Mobile | NaN | 中国台湾 | TA |
1681 | 2007 | 1682 | Evergreen Marine | 中国台湾(TA) | 运输 | 4.29 | 0.37 | 3.96 | 1.90 | Evergreen Marine | NaN | 中国台湾 | TA |
1692 | 2007 | 1693 | China Southern Airlines | 中国大陆(CN) | 运输 | 4.64 | -0.23 | 8.84 | 1.97 | China Southern Airlines | NaN | 中国大陆 | CN |
1705 | 2007 | 1706 | Cosco Pacific | 中国香港(HK)/中国大陆(CN) | 运输 | 0.30 | 0.34 | 2.85 | 5.94 | Cosco Pacific | NaN | 中国香港 | HK)/中国大陆(CN |
1710 | 2007 | 1711 | China Shipping Container | 中国大陆(CN) | 运输 | 3.52 | 0.44 | 3.59 | 2.26 | China Shipping Container | NaN | 中国大陆 | CN |
1736 | 2007 | 1737 | China Resources Power Holdings | 中国香港(HK)/中国大陆(CN) | 公用事业 | 0.76 | 0.37 | 3.67 | 5.37 | China Resources Power Holdings | NaN | 中国香港 | HK)/中国大陆(CN |
1739 | 2007 | 1740 | Citic Securities | 中国大陆(CN) | 综合金融 | 0.14 | 0.04 | 2.52 | 14.29 | Citic Securities | NaN | 中国大陆 | CN |
1780 | 2007 | 1781 | Far EasTone Telecom | 中国台湾(TA) | 电信运营商 | 2.19 | 0.45 | 3.01 | 4.45 | Far EasTone Telecom | NaN | 中国台湾 | TA |
1786 | 2007 | 1787 | E.Sun Financial | 中国台湾(TA) | 银行 | 0.73 | 0.14 | 19.36 | 2.19 | E.Sun Financial | NaN | 中国台湾 | TA |
1824 | 2007 | 1825 | Minmetals Development | 中国大陆(CN) | 贸易公司 | 8.25 | 0.04 | 3.46 | 1.50 | Minmetals Development | NaN | 中国大陆 | CN |
1840 | 2007 | 1841 | Shanghai Automotive | 中国大陆(CN) | 耐用消费品 | 0.79 | 0.14 | 1.81 | 11.10 | Shanghai Automotive | NaN | 中国大陆 | CN |
1846 | 2007 | 1847 | HK Exchanges & Clearing | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.35 | 0.17 | 2.96 | 10.97 | HK Exchanges & Clearing | NaN | 中国香港 | HK)/中国大陆(CN |
1852 | 2007 | 1853 | Link REIT | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.43 | 0.27 | 5.24 | 5.00 | Link REIT | NaN | 中国香港 | HK)/中国大陆(CN |
1860 | 2007 | 1861 | Kweichow Moutai | 中国大陆(CN) | 食品、饮料和烟草 | 0.43 | 0.14 | 1.00 | 10.69 | Kweichow Moutai | NaN | 中国大陆 | CN |
1892 | 2007 | 1892 | Yanzhou Coal Mining | 中国大陆(CN) | 材料 | 1.43 | 0.36 | 2.63 | 4.52 | Yanzhou Coal Mining | NaN | 中国大陆 | CN |
1908 | 2007 | 1909 | China Shipping Develop | 中国大陆(CN) | 运输 | 1.06 | 0.33 | 1.66 | 4.61 | China Shipping Develop | NaN | 中国大陆 | CN |
1920 | 2007 | 1920 | Wing Lung Bank | 中国香港(HK)/中国大陆(CN) | 银行 | 0.66 | 0.21 | 10.92 | 2.43 | Wing Lung Bank | NaN | 中国香港 | HK)/中国大陆(CN |
1922 | 2007 | 1923 | Delta Electronics | 中国台湾(TA) | 技术硬件和装备 | 2.46 | 0.23 | 2.49 | 6.40 | Delta Electronics | NaN | 中国台湾 | TA |
1945 | 2007 | 1946 | China Airlines | 中国台湾(TA) | 运输 | 3.61 | 0.02 | 7.63 | 1.85 | China Airlines | NaN | 中国台湾 | TA |
1948 | 2007 | 1949 | Wing Hang Bank | 中国香港(HK)/中国大陆(CN) | 银行 | 0.66 | 0.17 | 13.45 | 3.33 | Wing Hang Bank | NaN | 中国香港 | HK)/中国大陆(CN |
1959 | 2007 | 1959 | PCCW | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 2.90 | 0.21 | 6.87 | 3.98 | PCCW | NaN | 中国香港 | HK)/中国大陆(CN |
1960 | 2007 | 1961 | Benq | 中国台湾(TA) | 技术硬件和装备 | 5.39 | -0.16 | 5.04 | 1.27 | Benq | NaN | 中国台湾 | TA |
1963 | 2007 | 1964 | TCL Corp | 中国大陆(CN) | 技术硬件和装备 | 6.40 | -0.04 | 3.77 | 1.39 | TCL Corp | NaN | 中国大陆 | CN |
1970 | 2007 | 1971 | Wuliangye Yibin | 中国大陆(CN) | 食品、饮料和烟草 | 0.70 | 0.10 | 1.19 | 8.81 | Wuliangye Yibin | NaN | 中国大陆 | CN |
1973 | 2007 | 1974 | CNPC (Hong Kong) | 中国香港(HK)/中国大陆(CN) | 炼油 | 0.44 | 0.47 | 2.07 | 2.30 | CNPC (Hong Kong) | NaN | 中国香港 | HK)/中国大陆(CN |
1975 | 2007 | 1976 | K Wah International | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.04 | 0.47 | 1.29 | 0.98 | K Wah International | NaN | 中国香港 | HK)/中国大陆(CN |
1986 | 2007 | 1987 | China Overseas Land & Inv | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.90 | 0.20 | 3.24 | 7.05 | China Overseas Land & Inv | NaN | 中国香港 | HK)/中国大陆(CN |
1989 | 2007 | 1989 | Nine Dragons Paper Holdings | 中国香港(HK)/中国大陆(CN) | 材料 | 0.99 | 0.17 | 1.86 | 8.61 | Nine Dragons Paper Holdings | NaN | 中国香港 | HK)/中国大陆(CN |
131 rows × 13 columns
df_2007['Country_en'] = df_2007['Country_en'].replace(['HK.*','TA'],['CN-HK', 'CN-TA'],regex=True)
df_2007[df_2007['Country_en'].str.contains('CN',regex=True)]
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | Company_en | Company_cn | Country_cn | Country_en | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
40 | 2007 | 41 | PetroChina /中国石油 | 中国大陆(CN) | 炼油 | 68.43 | 16.53 | 96.42 | 208.76 | PetroChina | 中国石油 | 中国大陆 | CN |
52 | 2007 | 53 | ICBC /中国工商银行 | 中国大陆(CN) | 银行 | 31.98 | 4.65 | 800.04 | 176.03 | ICBC | 中国工商银行 | 中国大陆 | CN |
68 | 2007 | 69 | CCB-China Construction Bank /中国建设银行 | 中国大陆(CN) | 银行 | 23.18 | 5.84 | 568.21 | 126.55 | CCB-China Construction Bank | 中国建设银行 | 中国大陆 | CN |
70 | 2007 | 71 | Sinopec-China Petroleum /中石化 | 中国大陆(CN) | 炼油 | 99.03 | 5.07 | 65.83 | 93.57 | Sinopec-China Petroleum | 中石化 | 中国大陆 | CN |
81 | 2007 | 82 | Bank of China /中国银行 | 中国大陆(CN) | 银行 | 23.10 | 3.41 | 585.55 | 143.80 | Bank of China | 中国银行 | 中国大陆 | CN |
88 | 2007 | 89 | China Mobile /中国移动 | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 29.79 | 6.56 | 51.35 | 185.31 | China Mobile | 中国移动 | 中国香港 | CN-HK |
175 | 2007 | 176 | Hutchison Whampoa/和记黄埔 | 中国香港(HK)/中国大陆(CN) | 多元化 | 23.55 | 1.85 | 74.97 | 40.57 | Hutchison Whampoa | 和记黄埔 | 中国香港 | CN-HK |
180 | 2007 | 181 | China Telecom/中国电信 | 中国大陆(CN) | 电信运营商 | 20.98 | 3.46 | 50.34 | 37.50 | China Telecom | 中国电信 | 中国大陆 | CN |
242 | 2007 | 243 | China Life Insurance /中国人寿 | 中国大陆(CN) | 保险 | 11.18 | 1.15 | 69.30 | 109.96 | China Life Insurance | 中国人寿 | 中国大陆 | CN |
307 | 2007 | 308 | Bank of Communications/中国交通银行 | 中国大陆(CN) | 银行 | 6.64 | 1.15 | 176.27 | 46.14 | Bank of Communications | 中国交通银行 | 中国大陆 | CN |
309 | 2007 | 310 | Taiwan Semiconductor/台积电 | 中国台湾(TA) | 半导体 | 9.74 | 3.90 | 18.02 | 54.32 | Taiwan Semiconductor | 台积电 | 中国台湾 | CN-TA |
340 | 2007 | 341 | Hon Hai Precision Ind /鸿海精密 | 中国台湾(TA) | 技术硬件和装备 | 27.78 | 1.24 | 13.99 | 34.83 | Hon Hai Precision Ind | 鸿海精密 | 中国台湾 | CN-TA |
365 | 2007 | 366 | Baoshan Iron & Steel /上海宝钢集团 | 中国大陆(CN) | 材料 | 15.63 | 1.57 | 17.59 | 21.42 | Baoshan Iron & Steel | 上海宝钢集团 | 中国大陆 | CN |
388 | 2007 | 389 | Cathay Financial/国泰金融 | 中国台湾(TA) | 保险 | 10.09 | 0.66 | 93.29 | 19.87 | Cathay Financial | 国泰金融 | 中国台湾 | CN-TA |
394 | 2007 | 395 | Cnooc /中海油 | 中国香港(HK)/中国大陆(CN) | 炼油 | 8.51 | 3.10 | 14.22 | 34.94 | Cnooc | 中海油 | 中国香港 | CN-HK |
400 | 2007 | 401 | China Netcom Group /中国网通 | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 10.69 | 1.70 | 24.70 | 15.70 | China Netcom Group | 中国网通 | 中国香港 | CN-HK |
422 | 2007 | 423 | China Shenhua Energy/中国神华能源股份有限公司 | 中国大陆(CN) | 材料 | 6.47 | 1.94 | 17.08 | 45.94 | China Shenhua Energy | 中国神华能源股份有限公司 | 中国大陆 | CN |
429 | 2007 | 430 | BOC Hong Kong/中银香港 | 中国香港(HK)/中国大陆(CN) | 银行 | 4.13 | 1.74 | 106.03 | 25.58 | BOC Hong Kong | 中银香港 | 中国香港 | CN-HK |
436 | 2007 | 437 | Formosa Petrochemical/台塑石化 | 中国台湾(TA) | 炼油 | 13.56 | 1.74 | 12.35 | 19.28 | Formosa Petrochemical | 台塑石化 | 中国台湾 | CN-TA |
439 | 2007 | 440 | Ping An Insurance Group/平安保险 | 中国大陆(CN) | 保险 | 7.95 | 0.52 | 39.62 | 39.60 | Ping An Insurance Group | 平安保险 | 中国大陆 | CN |
451 | 2007 | 452 | Jardine Matheson/香港怡和集团 | 中国香港(HK)/中国大陆(CN) | 食品市场 | 11.96 | 1.25 | 18.34 | 13.59 | Jardine Matheson | 香港怡和集团 | 中国香港 | CN-HK |
510 | 2007 | 511 | Sun Hung Kai Properties /新鸿基房地产 | 中国香港(HK)/中国大陆(CN) | 综合金融 | 3.30 | 2.56 | 29.72 | 29.49 | Sun Hung Kai Properties | 新鸿基房地产 | 中国香港 | CN-HK |
541 | 2007 | 542 | China Unicom /中国联通 | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 10.67 | 0.60 | 17.63 | 16.03 | China Unicom | 中国联通 | 中国香港 | CN-HK |
551 | 2007 | 552 | CLP Holdings /中电控股 | 中国香港(HK)/中国大陆(CN) | 公用事业 | 5.87 | 1.27 | 16.42 | 17.65 | CLP Holdings | 中电控股 | 中国香港 | CN-HK |
575 | 2007 | 576 | Chunghwa Telecom/中华电信 | 中国台湾(TA) | 电信运营商 | 5.59 | 1.45 | 13.98 | 18.22 | Chunghwa Telecom | 中华电信 | 中国台湾 | CN-TA |
600 | 2007 | 601 | China Steel/台湾中钢公司 | 中国台湾(TA) | 材料 | 8.66 | 1.54 | 10.35 | 12.24 | China Steel | 台湾中钢公司 | 中国台湾 | CN-TA |
603 | 2007 | 604 | China Merchants Bank/招商银行 | 中国大陆(CN) | 银行 | 3.53 | 0.46 | 90.76 | 33.19 | China Merchants Bank | 招商银行 | 中国大陆 | CN |
617 | 2007 | 617 | Nan Ya Plastic/南亚塑胶工业 | 中国台湾(TA) | 化学制品 | 7.64 | 1.22 | 11.47 | 13.37 | Nan Ya Plastic | 南亚塑胶工业 | 中国台湾 | CN-TA |
627 | 2007 | 628 | Cheung Kong/长江集团 | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.80 | 1.80 | 28.01 | 28.39 | Cheung Kong | 长江集团 | 中国香港 | CN-HK |
736 | 2007 | 737 | Swire Pacific /太古集团 | 中国香港(HK)/中国大陆(CN) | 多元化 | 2.44 | 2.42 | 16.05 | 17.32 | Swire Pacific | 太古集团 | 中国香港 | CN-HK |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
1636 | 2007 | 1637 | Champion REIT | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.05 | 1.16 | 2.95 | 1.54 | Champion REIT | NaN | 中国香港 | CN-HK |
1641 | 2007 | 1642 | Noble Group | 中国香港(HK)/中国大陆(CN) | 运输 | 13.75 | 0.13 | 3.81 | 2.14 | Noble Group | NaN | 中国香港 | CN-HK |
1661 | 2007 | 1662 | Taiwan Mobile | 中国台湾(TA) | 电信运营商 | 1.81 | 0.50 | 3.59 | 4.84 | Taiwan Mobile | NaN | 中国台湾 | CN-TA |
1681 | 2007 | 1682 | Evergreen Marine | 中国台湾(TA) | 运输 | 4.29 | 0.37 | 3.96 | 1.90 | Evergreen Marine | NaN | 中国台湾 | CN-TA |
1692 | 2007 | 1693 | China Southern Airlines | 中国大陆(CN) | 运输 | 4.64 | -0.23 | 8.84 | 1.97 | China Southern Airlines | NaN | 中国大陆 | CN |
1705 | 2007 | 1706 | Cosco Pacific | 中国香港(HK)/中国大陆(CN) | 运输 | 0.30 | 0.34 | 2.85 | 5.94 | Cosco Pacific | NaN | 中国香港 | CN-HK |
1710 | 2007 | 1711 | China Shipping Container | 中国大陆(CN) | 运输 | 3.52 | 0.44 | 3.59 | 2.26 | China Shipping Container | NaN | 中国大陆 | CN |
1736 | 2007 | 1737 | China Resources Power Holdings | 中国香港(HK)/中国大陆(CN) | 公用事业 | 0.76 | 0.37 | 3.67 | 5.37 | China Resources Power Holdings | NaN | 中国香港 | CN-HK |
1739 | 2007 | 1740 | Citic Securities | 中国大陆(CN) | 综合金融 | 0.14 | 0.04 | 2.52 | 14.29 | Citic Securities | NaN | 中国大陆 | CN |
1780 | 2007 | 1781 | Far EasTone Telecom | 中国台湾(TA) | 电信运营商 | 2.19 | 0.45 | 3.01 | 4.45 | Far EasTone Telecom | NaN | 中国台湾 | CN-TA |
1786 | 2007 | 1787 | E.Sun Financial | 中国台湾(TA) | 银行 | 0.73 | 0.14 | 19.36 | 2.19 | E.Sun Financial | NaN | 中国台湾 | CN-TA |
1824 | 2007 | 1825 | Minmetals Development | 中国大陆(CN) | 贸易公司 | 8.25 | 0.04 | 3.46 | 1.50 | Minmetals Development | NaN | 中国大陆 | CN |
1840 | 2007 | 1841 | Shanghai Automotive | 中国大陆(CN) | 耐用消费品 | 0.79 | 0.14 | 1.81 | 11.10 | Shanghai Automotive | NaN | 中国大陆 | CN |
1846 | 2007 | 1847 | HK Exchanges & Clearing | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.35 | 0.17 | 2.96 | 10.97 | HK Exchanges & Clearing | NaN | 中国香港 | CN-HK |
1852 | 2007 | 1853 | Link REIT | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.43 | 0.27 | 5.24 | 5.00 | Link REIT | NaN | 中国香港 | CN-HK |
1860 | 2007 | 1861 | Kweichow Moutai | 中国大陆(CN) | 食品、饮料和烟草 | 0.43 | 0.14 | 1.00 | 10.69 | Kweichow Moutai | NaN | 中国大陆 | CN |
1892 | 2007 | 1892 | Yanzhou Coal Mining | 中国大陆(CN) | 材料 | 1.43 | 0.36 | 2.63 | 4.52 | Yanzhou Coal Mining | NaN | 中国大陆 | CN |
1908 | 2007 | 1909 | China Shipping Develop | 中国大陆(CN) | 运输 | 1.06 | 0.33 | 1.66 | 4.61 | China Shipping Develop | NaN | 中国大陆 | CN |
1920 | 2007 | 1920 | Wing Lung Bank | 中国香港(HK)/中国大陆(CN) | 银行 | 0.66 | 0.21 | 10.92 | 2.43 | Wing Lung Bank | NaN | 中国香港 | CN-HK |
1922 | 2007 | 1923 | Delta Electronics | 中国台湾(TA) | 技术硬件和装备 | 2.46 | 0.23 | 2.49 | 6.40 | Delta Electronics | NaN | 中国台湾 | CN-TA |
1945 | 2007 | 1946 | China Airlines | 中国台湾(TA) | 运输 | 3.61 | 0.02 | 7.63 | 1.85 | China Airlines | NaN | 中国台湾 | CN-TA |
1948 | 2007 | 1949 | Wing Hang Bank | 中国香港(HK)/中国大陆(CN) | 银行 | 0.66 | 0.17 | 13.45 | 3.33 | Wing Hang Bank | NaN | 中国香港 | CN-HK |
1959 | 2007 | 1959 | PCCW | 中国香港(HK)/中国大陆(CN) | 电信运营商 | 2.90 | 0.21 | 6.87 | 3.98 | PCCW | NaN | 中国香港 | CN-HK |
1960 | 2007 | 1961 | Benq | 中国台湾(TA) | 技术硬件和装备 | 5.39 | -0.16 | 5.04 | 1.27 | Benq | NaN | 中国台湾 | CN-TA |
1963 | 2007 | 1964 | TCL Corp | 中国大陆(CN) | 技术硬件和装备 | 6.40 | -0.04 | 3.77 | 1.39 | TCL Corp | NaN | 中国大陆 | CN |
1970 | 2007 | 1971 | Wuliangye Yibin | 中国大陆(CN) | 食品、饮料和烟草 | 0.70 | 0.10 | 1.19 | 8.81 | Wuliangye Yibin | NaN | 中国大陆 | CN |
1973 | 2007 | 1974 | CNPC (Hong Kong) | 中国香港(HK)/中国大陆(CN) | 炼油 | 0.44 | 0.47 | 2.07 | 2.30 | CNPC (Hong Kong) | NaN | 中国香港 | CN-HK |
1975 | 2007 | 1976 | K Wah International | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.04 | 0.47 | 1.29 | 0.98 | K Wah International | NaN | 中国香港 | CN-HK |
1986 | 2007 | 1987 | China Overseas Land & Inv | 中国香港(HK)/中国大陆(CN) | 综合金融 | 0.90 | 0.20 | 3.24 | 7.05 | China Overseas Land & Inv | NaN | 中国香港 | CN-HK |
1989 | 2007 | 1989 | Nine Dragons Paper Holdings | 中国香港(HK)/中国大陆(CN) | 材料 | 0.99 | 0.17 | 1.86 | 8.61 | Nine Dragons Paper Holdings | NaN | 中国香港 | CN-HK |
131 rows × 13 columns
df_2007['Industry_en'] = ''
df_2007.tail(5)
Year | Rank | Company_cn_en | Country_cn_en | Industry_cn | Sales | Profits | Assets | Market_value | Company_en | Company_cn | Country_cn | Country_en | Industry_en | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1995 | 2007 | 1995 | Fremont General | 美国(US) | 综合金融 | 1.25 | 0.17 | 12.80 | 0.69 | Fremont General | NaN | 美国 | US | |
1996 | 2007 | 1997 | United Rentals | 美国(US) | 商业服务和供应 | 3.64 | 0.22 | 5.37 | 2.32 | United Rentals | NaN | 美国 | US | |
1997 | 2007 | 1998 | CBOT Holdings | 美国(US) | 综合金融 | 0.64 | 0.17 | 0.81 | 8.54 | CBOT Holdings | NaN | 美国 | US | |
1998 | 2007 | 1998 | Singapore Petroleum | 新加坡(SI) | 炼油 | 5.59 | 0.19 | 2.05 | 1.50 | Singapore Petroleum | NaN | 新加坡 | SI | |
1999 | 2007 | 2000 | DVB Bank | 德国(GE) | 银行 | 0.77 | 0.06 | 12.74 | 1.26 | DVB Bank | NaN | 德国 | GE |
columns_sort = ['Year', 'Rank', 'Company_cn_en','Company_en',
'Company_cn', 'Country_cn_en', 'Country_cn',
'Country_en', 'Industry_cn', 'Industry_en',
'Sales', 'Profits', 'Assets', 'Market_value']
# 按指定list重新将columns进行排序
df_2007 = df_2007.reindex(columns=columns_sort)
print(df_2007.shape)
print(df_2007.dtypes)
df_2007.head(3)
(2000, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2007 | 1 | Citigroup /花旗集团 | Citigroup | 花旗集团 | 美国(US) | 美国 | US | 银行 | 146.56 | 21.54 | 1884.32 | 247.42 | |
1 | 2007 | 2 | Bank of America /美国银行 | Bank of America | 美国银行 | 美国(US) | 美国 | US | 银行 | 116.57 | 21.13 | 1459.74 | 226.61 | |
2 | 2007 | 3 | HSBC Holdings/汇丰集团 | HSBC Holdings | 汇丰集团 | 英国(UK) | 英国 | UK | 银行 | 121.51 | 16.63 | 1860.76 | 202.29 |
df_2008 = pd.read_csv('./data/data_forbes_2008.csv', encoding='gbk', thousands=',')
print('the shape of DataFrame: ', df_2008.shape)
print(df_2008.dtypes)
df_2008.head()
the shape of DataFrame: (2000, 10) 年份 int64 Rank int64 公司名称(英文) object 公司名称(中文) object Country/area(国家或地区) object Industry(行业) object Sales (销售额)($bil十亿美元) object Profits (利润)($bil) object Assets 资产($bil) object Market Value 市值($bil) float64 dtype: object
年份 | Rank | 公司名称(英文) | 公司名称(中文) | Country/area(国家或地区) | Industry(行业) | Sales (销售额)($bil十亿美元) | Profits (利润)($bil) | Assets 资产($bil) | Market Value 市值($bil) | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 2008 | 1 | HSBC Holdings | 汇丰集团 | United Kingdom | Banking | 146.5 | 19.13 | 2,348.98 | 180.81 |
1 | 2008 | 2 | General Electric | 通用电气公司 | United States | Conglomerates | 172.74 | 22.21 | 795.34 | 330.93 |
2 | 2008 | 3 | Bank of America | 美国银行 | United States | Banking | 119.19 | 14.98 | 1,715.75 | 176.53 |
3 | 2008 | 4 | JPMorgan Chase | 摩根大通公司 | United States | Banking | 116.35 | 15.37 | 1,562.15 | 136.88 |
4 | 2008 | 5 | ExxonMobil | 埃克森美孚公司 | United States | Oil & Gas Operations | 358.6 | 40.61 | 242.08 | 465.51 |
df_2008.columns = ['Year', 'Rank', 'Company_en', 'Company_cn','Country_en', 'Industry_en', 'Sales', 'Profits', 'Assets', 'Market_value']
df_2008.head()
Year | Rank | Company_en | Company_cn | Country_en | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 2008 | 1 | HSBC Holdings | 汇丰集团 | United Kingdom | Banking | 146.5 | 19.13 | 2,348.98 | 180.81 |
1 | 2008 | 2 | General Electric | 通用电气公司 | United States | Conglomerates | 172.74 | 22.21 | 795.34 | 330.93 |
2 | 2008 | 3 | Bank of America | 美国银行 | United States | Banking | 119.19 | 14.98 | 1,715.75 | 176.53 |
3 | 2008 | 4 | JPMorgan Chase | 摩根大通公司 | United States | Banking | 116.35 | 15.37 | 1,562.15 | 136.88 |
4 | 2008 | 5 | ExxonMobil | 埃克森美孚公司 | United States | Oil & Gas Operations | 358.6 | 40.61 | 242.08 | 465.51 |
df_2008['Company_cn_en'], df_2008['Country_cn_en'], df_2008['Country_cn'], df_2008['Industry_cn'] = ['','','','']
df_2008.head()
Year | Rank | Company_en | Company_cn | Country_en | Industry_en | Sales | Profits | Assets | Market_value | Company_cn_en | Country_cn_en | Country_cn | Industry_cn | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2008 | 1 | HSBC Holdings | 汇丰集团 | United Kingdom | Banking | 146.5 | 19.13 | 2,348.98 | 180.81 | ||||
1 | 2008 | 2 | General Electric | 通用电气公司 | United States | Conglomerates | 172.74 | 22.21 | 795.34 | 330.93 | ||||
2 | 2008 | 3 | Bank of America | 美国银行 | United States | Banking | 119.19 | 14.98 | 1,715.75 | 176.53 | ||||
3 | 2008 | 4 | JPMorgan Chase | 摩根大通公司 | United States | Banking | 116.35 | 15.37 | 1,562.15 | 136.88 | ||||
4 | 2008 | 5 | ExxonMobil | 埃克森美孚公司 | United States | Oil & Gas Operations | 358.6 | 40.61 | 242.08 | 465.51 |
col_digit = ['Sales', 'Profits', 'Assets', 'Market_value']
for col in col_digit:
# 将数字后面的字母进行替换
df_2008[col] = df_2008[col].replace('([A-Za-z])', '', regex=True)
# 千分位数字的逗号被识别为string了,需要替换
df_2008[col] = df_2008[col].replace(',', '', regex=True)
#将数字型字符串转换为可进行计算的数据类型
df_2008[col] = pd.to_numeric(df_2008[col])
# df_2008['Sales'] = pd.to_numeric(df_2008['Sales'])
# df_2008['Profits'] = pd.to_numeric(df_2008['Profits'])
# df_2008['Assets'] = pd.to_numeric(df_2008['Assets'])
# 按指定list重新将columns进行排序
df_2008 = df_2008.reindex(columns=columns_sort)
print(df_2008.shape)
print(df_2008.dtypes)
df_2008.head()
(2000, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2008 | 1 | HSBC Holdings | 汇丰集团 | United Kingdom | Banking | 146.50 | 19.13 | 2348.98 | 180.81 | ||||
1 | 2008 | 2 | General Electric | 通用电气公司 | United States | Conglomerates | 172.74 | 22.21 | 795.34 | 330.93 | ||||
2 | 2008 | 3 | Bank of America | 美国银行 | United States | Banking | 119.19 | 14.98 | 1715.75 | 176.53 | ||||
3 | 2008 | 4 | JPMorgan Chase | 摩根大通公司 | United States | Banking | 116.35 | 15.37 | 1562.15 | 136.88 | ||||
4 | 2008 | 5 | ExxonMobil | 埃克森美孚公司 | United States | Oil & Gas Operations | 358.60 | 40.61 | 242.08 | 465.51 |
df_2009 = pd.read_csv('./data/data_forbes_2009.csv', encoding='gbk')
print('the shape of DataFrame: ', df_2009.shape)
df_2009.head()
the shape of DataFrame: (2000, 9)
年份 | 排名(Rank) | 公司名称(Company) | 所在国家或地区(Country) | 所在行业(Industry) | 销售收入(Sales) ($bil) | 利润(Profits) | 总资产(Assets) ($bil) | 市值(Market Vaue) ($bil) | |
---|---|---|---|---|---|---|---|---|---|
0 | 2009 | 1 | General Electric/通用电气公司 | United States | Conglomerates | 182.52 | 17.41 | 797.77 | 89.87 |
1 | 2009 | 2 | Royal Dutch Shell/英荷壳牌集团 | Netherlands | Oil & Gas Operations | 458.36 | 26.28 | 278.44 | 135.10 |
2 | 2009 | 3 | Toyota Motor/丰田汽车公司 | Japan | Consumer Durables | 263.42 | 17.21 | 324.98 | 102.35 |
3 | 2009 | 4 | ExxonMobil/埃克森美孚公司 | United States | Oil & Gas Operations | 425.7 | 45.22 | 228.05 | 335.54 |
4 | 2009 | 5 | BP/英国石油公司 | United Kingdom | Oil & Gas Operations | 361.14 | 21.16 | 228.24 | 119.70 |
df_2009.columns = ['Year', 'Rank', 'Company_cn_en', 'Country_en', 'Industry_en', 'Sales', 'Profits', 'Assets', 'Market_value']
df_2009.head()
Year | Rank | Company_cn_en | Country_en | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
0 | 2009 | 1 | General Electric/通用电气公司 | United States | Conglomerates | 182.52 | 17.41 | 797.77 | 89.87 |
1 | 2009 | 2 | Royal Dutch Shell/英荷壳牌集团 | Netherlands | Oil & Gas Operations | 458.36 | 26.28 | 278.44 | 135.10 |
2 | 2009 | 3 | Toyota Motor/丰田汽车公司 | Japan | Consumer Durables | 263.42 | 17.21 | 324.98 | 102.35 |
3 | 2009 | 4 | ExxonMobil/埃克森美孚公司 | United States | Oil & Gas Operations | 425.7 | 45.22 | 228.05 | 335.54 |
4 | 2009 | 5 | BP/英国石油公司 | United Kingdom | Oil & Gas Operations | 361.14 | 21.16 | 228.24 | 119.70 |
df_2009['Company_en'],df_2009['Company_cn'] = df_2009['Company_cn_en'].str.split('/', 1).str
print(df_2009['Company_en'][:5])
print(df_2009['Company_cn'] [-5:])
df_2009.head()
0 General Electric 1 Royal Dutch Shell 2 Toyota Motor 3 ExxonMobil 4 BP Name: Company_en, dtype: object 1995 NaN 1996 NaN 1997 NaN 1998 NaN 1999 NaN Name: Company_cn, dtype: object
Year | Rank | Company_cn_en | Country_en | Industry_en | Sales | Profits | Assets | Market_value | Company_en | Company_cn | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2009 | 1 | General Electric/通用电气公司 | United States | Conglomerates | 182.52 | 17.41 | 797.77 | 89.87 | General Electric | 通用电气公司 |
1 | 2009 | 2 | Royal Dutch Shell/英荷壳牌集团 | Netherlands | Oil & Gas Operations | 458.36 | 26.28 | 278.44 | 135.10 | Royal Dutch Shell | 英荷壳牌集团 |
2 | 2009 | 3 | Toyota Motor/丰田汽车公司 | Japan | Consumer Durables | 263.42 | 17.21 | 324.98 | 102.35 | Toyota Motor | 丰田汽车公司 |
3 | 2009 | 4 | ExxonMobil/埃克森美孚公司 | United States | Oil & Gas Operations | 425.7 | 45.22 | 228.05 | 335.54 | ExxonMobil | 埃克森美孚公司 |
4 | 2009 | 5 | BP/英国石油公司 | United Kingdom | Oil & Gas Operations | 361.14 | 21.16 | 228.24 | 119.70 | BP | 英国石油公司 |
df_2009['Country_cn_en'], df_2009['Country_cn'], df_2009['Industry_cn'] = ['','','']
df_2009.head()
Year | Rank | Company_cn_en | Country_en | Industry_en | Sales | Profits | Assets | Market_value | Company_en | Company_cn | Country_cn_en | Country_cn | Industry_cn | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2009 | 1 | General Electric/通用电气公司 | United States | Conglomerates | 182.52 | 17.41 | 797.77 | 89.87 | General Electric | 通用电气公司 | |||
1 | 2009 | 2 | Royal Dutch Shell/英荷壳牌集团 | Netherlands | Oil & Gas Operations | 458.36 | 26.28 | 278.44 | 135.10 | Royal Dutch Shell | 英荷壳牌集团 | |||
2 | 2009 | 3 | Toyota Motor/丰田汽车公司 | Japan | Consumer Durables | 263.42 | 17.21 | 324.98 | 102.35 | Toyota Motor | 丰田汽车公司 | |||
3 | 2009 | 4 | ExxonMobil/埃克森美孚公司 | United States | Oil & Gas Operations | 425.7 | 45.22 | 228.05 | 335.54 | ExxonMobil | 埃克森美孚公司 | |||
4 | 2009 | 5 | BP/英国石油公司 | United Kingdom | Oil & Gas Operations | 361.14 | 21.16 | 228.24 | 119.70 | BP | 英国石油公司 |
col_digit = ['Sales', 'Profits', 'Assets', 'Market_value']
for col in col_digit:
# 将数字后面的字母进行替换
df_2009[col] = df_2009[col].replace('([A-Za-z])', '', regex=True)
# 千分位数字的逗号被识别为string了,需要替换
df_2009[col] = df_2009[col].replace(',', '', regex=True)
df_2009[col] = pd.to_numeric(df_2009[col])
# 按指定list重新将columns进行排序
df_2009 = df_2009.reindex(columns=columns_sort)
print(df_2009.shape)
print(df_2009.dtypes)
df_2009.head()
(2000, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2009 | 1 | General Electric/通用电气公司 | General Electric | 通用电气公司 | United States | Conglomerates | 182.52 | 17.41 | 797.77 | 89.87 | |||
1 | 2009 | 2 | Royal Dutch Shell/英荷壳牌集团 | Royal Dutch Shell | 英荷壳牌集团 | Netherlands | Oil & Gas Operations | 458.36 | 26.28 | 278.44 | 135.10 | |||
2 | 2009 | 3 | Toyota Motor/丰田汽车公司 | Toyota Motor | 丰田汽车公司 | Japan | Consumer Durables | 263.42 | 17.21 | 324.98 | 102.35 | |||
3 | 2009 | 4 | ExxonMobil/埃克森美孚公司 | ExxonMobil | 埃克森美孚公司 | United States | Oil & Gas Operations | 425.70 | 45.22 | 228.05 | 335.54 | |||
4 | 2009 | 5 | BP/英国石油公司 | BP | 英国石油公司 | United Kingdom | Oil & Gas Operations | 361.14 | 21.16 | 228.24 | 119.70 |
df_2010 = pd.read_csv('./data/data_forbes_2010.csv', encoding='gbk', header=None)
print('the shape of DataFrame: ', df_2010.shape)
df_2010.head()
the shape of DataFrame: (2001, 10)
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 2010 | 1 | 摩根大通公司 | JPMorgan Chase | United States | Banking | 115.63 | 11.65 | 2,031.99 | 166.19 |
1 | 2010 | 2 | 通用电气公司 | General Electric | United States | Conglomerates | 156.78 | 11.03 | 781.82 | 169.65 |
2 | 2010 | 3 | 美国银行 | Bank of America | United States | Banking | 150.45 | 6.28 | 2,223.30 | 167.63 |
3 | 2010 | 4 | 埃克森美孚公司 | ExxonMobil | United States | Oil & Gas Operations | 275.56 | 19.28 | 233.32 | 308.77 |
4 | 2010 | 5 | 中国工商银行 | ICBC | China | Banking | 71.86 | 16.27 | 1,428.46 | 242.23 |
df_2010.columns = ['Year', 'Rank', 'Company_cn','Company_en', 'Country_en',
'Industry_en', 'Sales', 'Profits', 'Assets', 'Market_value']
df_2010.head()
Year | Rank | Company_cn | Company_en | Country_en | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 2010 | 1 | 摩根大通公司 | JPMorgan Chase | United States | Banking | 115.63 | 11.65 | 2,031.99 | 166.19 |
1 | 2010 | 2 | 通用电气公司 | General Electric | United States | Conglomerates | 156.78 | 11.03 | 781.82 | 169.65 |
2 | 2010 | 3 | 美国银行 | Bank of America | United States | Banking | 150.45 | 6.28 | 2,223.30 | 167.63 |
3 | 2010 | 4 | 埃克森美孚公司 | ExxonMobil | United States | Oil & Gas Operations | 275.56 | 19.28 | 233.32 | 308.77 |
4 | 2010 | 5 | 中国工商银行 | ICBC | China | Banking | 71.86 | 16.27 | 1,428.46 | 242.23 |
df_2010['Company_cn_en'], df_2010['Country_cn_en'], df_2010['Country_cn'], df_2010['Industry_cn'] = ['','','','']
df_2010.head()
Year | Rank | Company_cn | Company_en | Country_en | Industry_en | Sales | Profits | Assets | Market_value | Company_cn_en | Country_cn_en | Country_cn | Industry_cn | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2010 | 1 | 摩根大通公司 | JPMorgan Chase | United States | Banking | 115.63 | 11.65 | 2,031.99 | 166.19 | ||||
1 | 2010 | 2 | 通用电气公司 | General Electric | United States | Conglomerates | 156.78 | 11.03 | 781.82 | 169.65 | ||||
2 | 2010 | 3 | 美国银行 | Bank of America | United States | Banking | 150.45 | 6.28 | 2,223.30 | 167.63 | ||||
3 | 2010 | 4 | 埃克森美孚公司 | ExxonMobil | United States | Oil & Gas Operations | 275.56 | 19.28 | 233.32 | 308.77 | ||||
4 | 2010 | 5 | 中国工商银行 | ICBC | China | Banking | 71.86 | 16.27 | 1,428.46 | 242.23 |
df_2010 = df_2010.drop(1600)
# df_2010.drop(1600, inplace=True)
col_digit = ['Sales', 'Profits', 'Assets', 'Market_value', 'Rank']
for col in col_digit:
# 将数字后面的字母进行替换
df_2010[col] = df_2010[col].replace('([A-Za-z])', '', regex=True)
# 千分位数字的逗号被识别为string了,需要替换
df_2010[col] = df_2010[col].replace(',', '', regex=True)
df_2010[col] = pd.to_numeric(df_2010[col])
# 按指定list重新将columns进行排序
df_2010 = df_2010.reindex(columns=columns_sort)
print(df_2010.shape)
print(df_2010.dtypes)
df_2010.head()
(2000, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2010 | 1 | JPMorgan Chase | 摩根大通公司 | United States | Banking | 115.63 | 11.65 | 2031.99 | 166.19 | ||||
1 | 2010 | 2 | General Electric | 通用电气公司 | United States | Conglomerates | 156.78 | 11.03 | 781.82 | 169.65 | ||||
2 | 2010 | 3 | Bank of America | 美国银行 | United States | Banking | 150.45 | 6.28 | 2223.30 | 167.63 | ||||
3 | 2010 | 4 | ExxonMobil | 埃克森美孚公司 | United States | Oil & Gas Operations | 275.56 | 19.28 | 233.32 | 308.77 | ||||
4 | 2010 | 5 | ICBC | 中国工商银行 | China | Banking | 71.86 | 16.27 | 1428.46 | 242.23 |
# df_2010.to_csv('data_forbes_2010_update.csv')
df_2011 = pd.read_csv('./data/data_forbes_2011.csv', encoding='gbk', header=None, thousands=',')
print('the shape of DataFrame: ', df_2011.shape)
df_2011.head()
the shape of DataFrame: (2000, 10)
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 2011 | 1 | JPMorgan Chase | 摩根大通 | 美国 | 银行 | 1155 | 174 | 21176 | 1822 |
1 | 2011 | 2 | HSBC Holdings | 汇丰控股 | 英国 | 银行 | 1033 | 133 | 24679 | 1865 |
2 | 2011 | 3 | General Electric | 通用电气 | 美国 | 企业集团 | 1502 | 116 | 7512 | 2162 |
3 | 2011 | 4 | ExxonMobil | 埃克森美孚 | 美国 | 石油天然气 | 3416 | 305 | 3025 | 4072 |
4 | 2011 | 5 | Royal Dutch Shell | 皇家荷兰壳牌集团 | 荷兰 | 石油天然气 | 3691 | 201 | 3172 | 2129 |
df_2011.columns = ['Year', 'Rank', 'Company_en','Company_cn', 'Country_cn',
'Industry_cn', 'Sales', 'Profits', 'Assets', 'Market_value']
df_2011.head()
Year | Rank | Company_en | Company_cn | Country_cn | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 2011 | 1 | JPMorgan Chase | 摩根大通 | 美国 | 银行 | 1155 | 174 | 21176 | 1822 |
1 | 2011 | 2 | HSBC Holdings | 汇丰控股 | 英国 | 银行 | 1033 | 133 | 24679 | 1865 |
2 | 2011 | 3 | General Electric | 通用电气 | 美国 | 企业集团 | 1502 | 116 | 7512 | 2162 |
3 | 2011 | 4 | ExxonMobil | 埃克森美孚 | 美国 | 石油天然气 | 3416 | 305 | 3025 | 4072 |
4 | 2011 | 5 | Royal Dutch Shell | 皇家荷兰壳牌集团 | 荷兰 | 石油天然气 | 3691 | 201 | 3172 | 2129 |
df_2011.dtypes
Year int64 Rank int64 Company_en object Company_cn object Country_cn object Industry_cn object Sales int64 Profits int64 Assets int64 Market_value int64 dtype: object
df_2011[['Sales','Profits','Assets','Market_value']] =df_2011[['Sales','Profits','Assets','Market_value']].apply(lambda x: x/10)
df_2011.head()
Year | Rank | Company_en | Company_cn | Country_cn | Industry_cn | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 2011 | 1 | JPMorgan Chase | 摩根大通 | 美国 | 银行 | 115.5 | 17.4 | 2117.6 | 182.2 |
1 | 2011 | 2 | HSBC Holdings | 汇丰控股 | 英国 | 银行 | 103.3 | 13.3 | 2467.9 | 186.5 |
2 | 2011 | 3 | General Electric | 通用电气 | 美国 | 企业集团 | 150.2 | 11.6 | 751.2 | 216.2 |
3 | 2011 | 4 | ExxonMobil | 埃克森美孚 | 美国 | 石油天然气 | 341.6 | 30.5 | 302.5 | 407.2 |
4 | 2011 | 5 | Royal Dutch Shell | 皇家荷兰壳牌集团 | 荷兰 | 石油天然气 | 369.1 | 20.1 | 317.2 | 212.9 |
df_2011['Company_cn_en'], df_2011['Country_cn_en'], df_2011['Country_en'], df_2011['Industry_en'] = ['','','','']
df_2011.head()
Year | Rank | Company_en | Company_cn | Country_cn | Industry_cn | Sales | Profits | Assets | Market_value | Company_cn_en | Country_cn_en | Country_en | Industry_en | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2011 | 1 | JPMorgan Chase | 摩根大通 | 美国 | 银行 | 115.5 | 17.4 | 2117.6 | 182.2 | ||||
1 | 2011 | 2 | HSBC Holdings | 汇丰控股 | 英国 | 银行 | 103.3 | 13.3 | 2467.9 | 186.5 | ||||
2 | 2011 | 3 | General Electric | 通用电气 | 美国 | 企业集团 | 150.2 | 11.6 | 751.2 | 216.2 | ||||
3 | 2011 | 4 | ExxonMobil | 埃克森美孚 | 美国 | 石油天然气 | 341.6 | 30.5 | 302.5 | 407.2 | ||||
4 | 2011 | 5 | Royal Dutch Shell | 皇家荷兰壳牌集团 | 荷兰 | 石油天然气 | 369.1 | 20.1 | 317.2 | 212.9 |
# 按指定list重新将columns进行排序
df_2011 = df_2011.reindex(columns=columns_sort)
print(df_2011.shape)
print(df_2011.dtypes)
df_2011.head()
(2000, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2011 | 1 | JPMorgan Chase | 摩根大通 | 美国 | 银行 | 115.5 | 17.4 | 2117.6 | 182.2 | ||||
1 | 2011 | 2 | HSBC Holdings | 汇丰控股 | 英国 | 银行 | 103.3 | 13.3 | 2467.9 | 186.5 | ||||
2 | 2011 | 3 | General Electric | 通用电气 | 美国 | 企业集团 | 150.2 | 11.6 | 751.2 | 216.2 | ||||
3 | 2011 | 4 | ExxonMobil | 埃克森美孚 | 美国 | 石油天然气 | 341.6 | 30.5 | 302.5 | 407.2 | ||||
4 | 2011 | 5 | Royal Dutch Shell | 皇家荷兰壳牌集团 | 荷兰 | 石油天然气 | 369.1 | 20.1 | 317.2 | 212.9 |
df_2012 = pd.read_csv('./data/data_forbes_2012.csv', encoding='gbk',header=None)
print('the shape of DataFrame: ', df_2012.shape)
print(df_2012.dtypes)
df_2012.head()
the shape of DataFrame: (2000, 9) 0 int64 1 int64 2 float64 3 object 4 object 5 int64 6 int64 7 int64 8 float64 dtype: object
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
---|---|---|---|---|---|---|---|---|---|
0 | 2012 | 1 | NaN | 埃克森美孚/Exxon Mobil | 美国 | 4335 | 411 | 3311 | 4074.0 |
1 | 2012 | 2 | NaN | 摩根大通/JPMorgan Chase | 美国 | 1108 | 190 | 22658 | 1701.0 |
2 | 2012 | 3 | NaN | 通用电气/General Electric | 美国 | 1473 | 142 | 7172 | 2137.0 |
3 | 2012 | 4 | NaN | 皇家荷兰壳牌集团/Royal Dutch Shell | 荷兰 | 4702 | 309 | 3405 | 2276.0 |
4 | 2012 | 5 | NaN | 中国工商银行/ICBC | 中国 | 826 | 251 | 20391 | 2374.0 |
# 更新列名
df_2012.columns = ['Year', 'Rank', 'Company_cn','Company_cn_en',
'Country_cn', 'Sales', 'Profits', 'Assets', 'Market_value']
# 拆分"Company_cn_en"列,新生成两列,分别为公司英文名称和中文名称
df_2012['Company_cn'],df_2012['Company_en'] = df_2012['Company_cn_en'].str.split('/', 1).str
# print(df_2012['Company_cn'][:5])
# print(df_2012['Company_en'] [-5:])
# 将数据单位转换成十亿美元
df_2012[['Sales','Profits','Assets','Market_value']] =df_2012[['Sales','Profits','Assets','Market_value']].apply(lambda x: x/10)
# 添加空白列
df_2012['Country_en'],df_2012['Country_cn_en'], df_2012['Industry_cn'], df_2012['Industry_en'] = ['','','','']
# 按指定list重新将columns进行排序
df_2012 = df_2012.reindex(columns=columns_sort)
print(df_2012.shape)
print(df_2012.dtypes)
df_2012.head()
(2000, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2012 | 1 | 埃克森美孚/Exxon Mobil | Exxon Mobil | 埃克森美孚 | 美国 | 433.5 | 41.1 | 331.1 | 407.4 | ||||
1 | 2012 | 2 | 摩根大通/JPMorgan Chase | JPMorgan Chase | 摩根大通 | 美国 | 110.8 | 19.0 | 2265.8 | 170.1 | ||||
2 | 2012 | 3 | 通用电气/General Electric | General Electric | 通用电气 | 美国 | 147.3 | 14.2 | 717.2 | 213.7 | ||||
3 | 2012 | 4 | 皇家荷兰壳牌集团/Royal Dutch Shell | Royal Dutch Shell | 皇家荷兰壳牌集团 | 荷兰 | 470.2 | 30.9 | 340.5 | 227.6 | ||||
4 | 2012 | 5 | 中国工商银行/ICBC | ICBC | 中国工商银行 | 中国 | 82.6 | 25.1 | 2039.1 | 237.4 |
df_2013 = pd.read_csv('./data/data_forbes_2013.csv', encoding='gbk',header=None)
print('the shape of DataFrame: ', df_2013.shape)
print(df_2013.dtypes)
df_2013.head()
the shape of DataFrame: (1991, 9) 0 int64 1 int64 2 float64 3 object 4 object 5 object 6 object 7 object 8 object dtype: object
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
---|---|---|---|---|---|---|---|---|---|
0 | 2013 | 1 | NaN | 中国工商银行/ICBC | 中国大陆 | 1348 | 378 | 28135 | 2373 |
1 | 2013 | 2 | NaN | 中国建设银行/China Construction Bank | 中国大陆 | 1131 | 306 | 22410 | 2020 |
2 | 2013 | 3 | NaN | 摩根大通/JPMorgan Chase | 美国 | 1082 | 213 | 23591 | 1914 |
3 | 2013 | 4 | NaN | 通用电气/General Electric | 美国 | 1474 | 136 | 6853 | 2437 |
4 | 2013 | 5 | NaN | 埃克森美孚/Exxon Mobil | 美国 | 4207 | 449 | 3338 | 4004 |
df_2013_economy = pd.read_csv('./data/data_forbes_2013_economywatch.csv', encoding='gbk')
print('the shape of DataFrame: ', df_2013_economy.shape)
print(df_2013_economy.dtypes)
df_2013_economy.head()
the shape of DataFrame: (1984, 7) Global Rank int64 Company object Country object Sales\n ($billion) float64 Profits\n ($billion) float64 Assets\n ($billion) float64 Market Value\n ($billion) float64 dtype: object
Global Rank | Company | Country | Sales ($billion) | Profits ($billion) | Assets ($billion) | Market Value ($billion) | |
---|---|---|---|---|---|---|---|
0 | 1 | ICBC | China | 134.8 | 37.8 | 2813.5 | 237.3 |
1 | 2 | China Construction Bank | China | 113.1 | 30.6 | 2241.0 | 202.0 |
2 | 8 | Agricultural Bank of China | China | 103.0 | 23.0 | 2124.2 | 150.8 |
3 | 9 | PetroChina | China | 308.9 | 18.3 | 347.8 | 261.2 |
4 | 11 | Bank of China | China | 98.1 | 22.1 | 2033.8 | 131.7 |
df_2013_all = pd.read_excel('./data/data_forbes_2013_all.xlsx')
print('the shape of DataFrame: ', df_2013_all.shape)
print(df_2013_all.dtypes)
df_2013_all.head()
the shape of DataFrame: (2000, 7) 排名 int64 公司名 object 国家(地区) object 销售额(亿美元) int64 利润(亿美元) int64 资产(亿美元) int64 市值(亿美元) int64 dtype: object
排名 | 公司名 | 国家(地区) | 销售额(亿美元) | 利润(亿美元) | 资产(亿美元) | 市值(亿美元) | |
---|---|---|---|---|---|---|---|
0 | 1 | 中国工商银行/ICBC | 中国大陆 | 1348 | 378 | 28135 | 2373 |
1 | 2 | 中国建设银行/China Construction Bank | 中国大陆 | 1131 | 306 | 22410 | 2020 |
2 | 3 | 摩根大通/JPMorgan Chase | 美国 | 1082 | 213 | 23591 | 1914 |
3 | 4 | 通用电气/General Electric | 美国 | 1474 | 136 | 6853 | 2437 |
4 | 5 | 埃克森美孚/Exxon Mobil | 美国 | 4207 | 449 | 3338 | 4004 |
# 更新列名
df_2013_all.columns = ['Rank', 'Company_cn_en',
'Country_cn', 'Sales', 'Profits', 'Assets', 'Market_value']
# 拆分"Company_cn_en"列,新生成两列,分别为公司英文名称和中文名称
df_2013_all['Company_cn'],df_2013_all['Company_en'] = df_2013_all['Company_cn_en'].str.split('/', 1).str
# print(df_2013_all['Company_cn'][:5])
# print(df_2013_all['Company_en'] [-5:])
# 将数据单位转换成十亿美元
df_2013_all[['Sales','Profits','Assets','Market_value']] =df_2013_all[['Sales','Profits','Assets','Market_value']].apply(lambda x: x/10)
# 添加年份2013
df_2013_all['Year'] = 2013
# 添加空白列
df_2013_all['Country_en'],df_2013_all['Country_cn_en'], df_2013_all['Industry_cn'], df_2013_all['Industry_en'] = ['','','','']
df_2013_all['Rank'] = pd.to_numeric(df_2013_all['Rank'])
# 按指定list重新将columns进行排序
df_2013_all = df_2013_all.reindex(columns=columns_sort)
print(df_2013_all.shape)
print(df_2013_all.dtypes)
df_2013_all.head()
(2000, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2013 | 1 | 中国工商银行/ICBC | ICBC | 中国工商银行 | 中国大陆 | 134.8 | 37.8 | 2813.5 | 237.3 | ||||
1 | 2013 | 2 | 中国建设银行/China Construction Bank | China Construction Bank | 中国建设银行 | 中国大陆 | 113.1 | 30.6 | 2241.0 | 202.0 | ||||
2 | 2013 | 3 | 摩根大通/JPMorgan Chase | JPMorgan Chase | 摩根大通 | 美国 | 108.2 | 21.3 | 2359.1 | 191.4 | ||||
3 | 2013 | 4 | 通用电气/General Electric | General Electric | 通用电气 | 美国 | 147.4 | 13.6 | 685.3 | 243.7 | ||||
4 | 2013 | 5 | 埃克森美孚/Exxon Mobil | Exxon Mobil | 埃克森美孚 | 美国 | 420.7 | 44.9 | 333.8 | 400.4 |
# columns_sort = ['Year', 'Rank', 'Company_cn_en','Company_en','Company_cn', 'Country_cn_en', 'Country_cn', 'Country_en', 'Industry_cn', 'Industry_en','Sales', 'Profits', 'Assets', 'Market_value']
df_2014 = pd.read_csv('./data/data_forbes_2014.csv', encoding='gbk',header=None)
print('the shape of DataFrame: ', df_2014.shape)
print(df_2014.dtypes)
df_2014.head()
the shape of DataFrame: (2000, 9) 0 int64 1 int64 2 float64 3 object 4 object 5 int64 6 int64 7 int64 8 int64 dtype: object
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
---|---|---|---|---|---|---|---|---|---|
0 | 2014 | 1 | NaN | 中国工商银行/ICBC | 中国大陆 | 1487 | 427 | 31249 | 2156 |
1 | 2014 | 2 | NaN | 中国建设银行/China Construction Bank | 中国大陆 | 1213 | 342 | 24495 | 1744 |
2 | 2014 | 3 | NaN | 中国农业银行/Agricultural Bank of China | 中国大陆 | 1364 | 270 | 24054 | 1411 |
3 | 2014 | 4 | NaN | 摩根大通/JPMorgan Chase | 美国 | 1057 | 173 | 24353 | 2297 |
4 | 2014 | 5 | NaN | 伯克希尔哈撒韦/Berkshire Hathaway | 美国 | 1788 | 195 | 4934 | 3091 |
# 更新列名
df_2014.columns = ['Year', 'Rank', 'Company_cn','Company_cn_en',
'Country_cn', 'Sales', 'Profits', 'Assets', 'Market_value']
# 拆分"Company_cn_en"列,新生成两列,分别为公司英文名称和中文名称
df_2014['Company_cn'],df_2014['Company_en'] = df_2014['Company_cn_en'].str.split('/', 1).str
# print(df_2014['Company_cn'][:5])
# print(df_2014['Company_en'] [-5:])
# 将数据单位转换成十亿美元
df_2014[['Sales','Profits','Assets','Market_value']] =df_2014[['Sales','Profits','Assets','Market_value']].apply(lambda x: x/10)
# 添加空白列
df_2014['Country_en'],df_2014['Country_cn_en'], df_2014['Industry_cn'], df_2014['Industry_en'] = ['','','','']
# 按指定list重新将columns进行排序
df_2014 = df_2014.reindex(columns=columns_sort)
print(df_2014.shape)
df_2014.head()
(2000, 14)
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2014 | 1 | 中国工商银行/ICBC | ICBC | 中国工商银行 | 中国大陆 | 148.7 | 42.7 | 3124.9 | 215.6 | ||||
1 | 2014 | 2 | 中国建设银行/China Construction Bank | China Construction Bank | 中国建设银行 | 中国大陆 | 121.3 | 34.2 | 2449.5 | 174.4 | ||||
2 | 2014 | 3 | 中国农业银行/Agricultural Bank of China | Agricultural Bank of China | 中国农业银行 | 中国大陆 | 136.4 | 27.0 | 2405.4 | 141.1 | ||||
3 | 2014 | 4 | 摩根大通/JPMorgan Chase | JPMorgan Chase | 摩根大通 | 美国 | 105.7 | 17.3 | 2435.3 | 229.7 | ||||
4 | 2014 | 5 | 伯克希尔哈撒韦/Berkshire Hathaway | Berkshire Hathaway | 伯克希尔哈撒韦 | 美国 | 178.8 | 19.5 | 493.4 | 309.1 |
df_2015 = pd.read_csv('./data/data_forbes_2015.csv', encoding='gbk',header=None)
print('the shape of DataFrame: ', df_2015.shape)
print(df_2015.dtypes)
df_2015.head()
the shape of DataFrame: (2020, 9) 0 int64 1 int64 2 float64 3 object 4 object 5 float64 6 float64 7 float64 8 float64 dtype: object
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
---|---|---|---|---|---|---|---|---|---|
0 | 2015 | 1 | NaN | 中国工商银行/ICBC | 中国大陆 | 1668.0 | 448.0 | 33220.0 | 2783.0 |
1 | 2015 | 2 | NaN | 中国建设银行/China Construction Bank | 中国大陆 | 1305.0 | 370.0 | 26989.0 | 2129.0 |
2 | 2015 | 3 | NaN | 中国农业银行/Agricultural Bank of China | 中国大陆 | 1292.0 | 291.0 | 25748.0 | 1899.0 |
3 | 2015 | 4 | NaN | 中国银行/Bank of China | 中国大陆 | 1203.0 | 275.0 | 24583.0 | 1991.0 |
4 | 2015 | 5 | NaN | 伯克希尔哈撒韦/Berkshire Hathaway | 美国 | 1947.0 | 199.0 | 5346.0 | 3548.0 |
# 更新列名
df_2015.columns = ['Year', 'Rank', 'Company_cn','Company_cn_en',
'Country_cn', 'Sales', 'Profits', 'Assets', 'Market_value']
# 拆分"Company_cn_en"列,新生成两列,分别为公司英文名称和中文名称
df_2015['Company_cn'],df_2015['Company_en'] = df_2015['Company_cn_en'].str.split('/', 1).str
# print(df_2014['Company_cn'][:5])
# print(df_2014['Company_en'] [-5:])
# 将数据单位转换成十亿美元
df_2015[['Sales','Profits','Assets','Market_value']] =df_2015[['Sales','Profits','Assets','Market_value']].apply(lambda x: x/10)
# 添加空白列
df_2015['Country_en'],df_2015['Country_cn_en'], df_2015['Industry_cn'], df_2015['Industry_en'] = ['','','','']
# 按指定list重新将columns进行排序
df_2015 = df_2015.reindex(columns=columns_sort)
print(df_2015.shape)
df_2015.head()
(2020, 14)
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2015 | 1 | 中国工商银行/ICBC | ICBC | 中国工商银行 | 中国大陆 | 166.8 | 44.8 | 3322.0 | 278.3 | ||||
1 | 2015 | 2 | 中国建设银行/China Construction Bank | China Construction Bank | 中国建设银行 | 中国大陆 | 130.5 | 37.0 | 2698.9 | 212.9 | ||||
2 | 2015 | 3 | 中国农业银行/Agricultural Bank of China | Agricultural Bank of China | 中国农业银行 | 中国大陆 | 129.2 | 29.1 | 2574.8 | 189.9 | ||||
3 | 2015 | 4 | 中国银行/Bank of China | Bank of China | 中国银行 | 中国大陆 | 120.3 | 27.5 | 2458.3 | 199.1 | ||||
4 | 2015 | 5 | 伯克希尔哈撒韦/Berkshire Hathaway | Berkshire Hathaway | 伯克希尔哈撒韦 | 美国 | 194.7 | 19.9 | 534.6 | 354.8 |
# 数据有2020行,有重复行,需要去除重复行
# inplace=True,使去重生效
df_2015.drop_duplicates('Company_cn_en', inplace=True)
# 查看'Company_cn_en'是否还有重复行
df_2015[df_2015['Company_cn_en'].duplicated()]
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value |
---|
print('the shape of DataFrame: ', df_2015.shape)
# print(df_2015.dtypes)
# df_2015.head()
the shape of DataFrame: (2000, 14)
df_2016 = pd.read_csv('./data/data_forbes_2016.csv', encoding='gbk',header=None)
print('the shape of DataFrame: ', df_2016.shape)
# 更新列名
df_2016.columns = ['Year', 'Rank', 'Company_cn','Company_en',
'Country_en', 'Sales', 'Profits', 'Assets', 'Market_value']
print(df_2016.dtypes)
df_2016.head()
the shape of DataFrame: (2001, 9) Year int64 Rank int64 Company_cn float64 Company_en object Country_en object Sales object Profits object Assets object Market_value object dtype: object
Year | Rank | Company_cn | Company_en | Country_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
0 | 2016 | 1 | NaN | ICBC | China | $171.1 B | $44.2 B | $3,420.3 B | $198 B |
1 | 2016 | 2 | NaN | China Construction Bank | China | $146.8 B | $36.4 B | $2,826 B | $162.8 B |
2 | 2016 | 3 | NaN | Agricultural Bank of China | China | $131.9 B | $28.8 B | $2,739.8 B | $152.7 B |
3 | 2016 | 4 | NaN | Berkshire Hathaway | United States | $210.8 B | $24.1 B | $561.1 B | $360.1 B |
4 | 2016 | 5 | NaN | JPMorgan Chase | United States | $99.9 B | $23.5 B | $2,423.8 B | $234.2 B |
def pro_col(df, col):
# 替换相关字符串,如有更多的替换情形,可以自行添加
df[col] = df[col].str.replace('$','')
df[col] = df[col].str.replace('^[A-Za-z]+$','')
df[col] = df[col].str.replace('B','')
# 注意这里是'-$',即以'-'结尾,而不是'-',因为有负数
df[col] = df[col].str.replace('-$','')
df[col] = df[col].str.replace(',','')
# 处理含有百万“M”为单位的数据,即以“M”结尾的数据
# 思路:
# (1)设定查找条件mask;
# (2)替换字符串“M”为空值
# (3)用pd.to_numeric()转换为数字
# (4)除以1000,转换为十亿美元,与其他行的数据一致
mask = df[col].str.endswith('M')
df.loc[mask, col] = pd.to_numeric(df.loc[mask, col].str.replace('M',''))/1000
# 将字符型的数字转换为数字类型
df[col] = pd.to_numeric(df[col])
return df
# pro_col(df_2016, 'Sales')
# pro_col(df_2016, 'Profits')
# pro_col(df_2016, 'Assets')
# pro_col(df_2016, 'Market_value')
cols = ['Sales', 'Profits', 'Assets', 'Market_value']
for col in cols:
pro_col(df_2016, col)
print('the shape of DataFrame: ', df_2016.shape)
print(df_2016.dtypes)
df_2016.head()
the shape of DataFrame: (2001, 9) Year int64 Rank int64 Company_cn float64 Company_en object Country_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn | Company_en | Country_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
0 | 2016 | 1 | NaN | ICBC | China | 171.1 | 44.2 | 3420.3 | 198.0 |
1 | 2016 | 2 | NaN | China Construction Bank | China | 146.8 | 36.4 | 2826.0 | 162.8 |
2 | 2016 | 3 | NaN | Agricultural Bank of China | China | 131.9 | 28.8 | 2739.8 | 152.7 |
3 | 2016 | 4 | NaN | Berkshire Hathaway | United States | 210.8 | 24.1 | 561.1 | 360.1 |
4 | 2016 | 5 | NaN | JPMorgan Chase | United States | 99.9 | 23.5 | 2423.8 | 234.2 |
# 添加空白列
df_2016['Company_cn_en'],df_2016['Country_cn_en'], df_2016['Country_cn'], df_2016['Industry_cn'], df_2016['Industry_en'] = ['','','','','']
# 按指定list重新将columns进行排序
df_2016 = df_2016.reindex(columns=columns_sort)
print(df_2016.shape)
df_2016.head()
(2001, 14)
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2016 | 1 | ICBC | NaN | China | 171.1 | 44.2 | 3420.3 | 198.0 | |||||
1 | 2016 | 2 | China Construction Bank | NaN | China | 146.8 | 36.4 | 2826.0 | 162.8 | |||||
2 | 2016 | 3 | Agricultural Bank of China | NaN | China | 131.9 | 28.8 | 2739.8 | 152.7 | |||||
3 | 2016 | 4 | Berkshire Hathaway | NaN | United States | 210.8 | 24.1 | 561.1 | 360.1 | |||||
4 | 2016 | 5 | JPMorgan Chase | NaN | United States | 99.9 | 23.5 | 2423.8 | 234.2 |
df_2017 = pd.read_csv('./data/data_forbes_2017.csv', encoding='gbk')
# 更新列名
df_2017.columns = ['Year', 'Rank', 'Company_cn','Company_en',
'Country_en', 'Sales', 'Profits', 'Assets', 'Market_value']
print('the shape of DataFrame: ', df_2017.shape)
df_2017.head()
the shape of DataFrame: (2000, 9)
Year | Rank | Company_cn | Company_en | Country_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
0 | 2017 | 1 | 中国工商银行 | ICBC | China | $151.4 B | $42 B | $3,473.2 B | $229.8 B |
1 | 2017 | 2 | 中国建设银行 | China Construction Bank | China | $134.2 B | $35 B | $3,016.6 B | $200.5 B |
2 | 2017 | 3 | 伯克希尔哈撒韦 | Berkshire Hathaway | United States | $222.9 B | $24.1 B | $620.9 B | $409.9 B |
3 | 2017 | 4 | 摩根大通 | JPMorgan Chase | United States | $102.5 B | $24.2 B | $2,513 B | $306.6 B |
4 | 2017 | 5 | 富国银行 | Wells Fargo | United States | $97.6 B | $21.9 B | $1,943.4 B | $274.4 B |
cols = ['Sales', 'Profits', 'Assets', 'Market_value']
for col in cols:
pro_col(df_2017, col)
print('the shape of DataFrame: ', df_2017.shape)
print(df_2017.dtypes)
df_2017.head()
the shape of DataFrame: (2000, 9) Year int64 Rank int64 Company_cn object Company_en object Country_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
Year | Rank | Company_cn | Company_en | Country_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|
0 | 2017 | 1 | 中国工商银行 | ICBC | China | 151.4 | 42.0 | 3473.2 | 229.8 |
1 | 2017 | 2 | 中国建设银行 | China Construction Bank | China | 134.2 | 35.0 | 3016.6 | 200.5 |
2 | 2017 | 3 | 伯克希尔哈撒韦 | Berkshire Hathaway | United States | 222.9 | 24.1 | 620.9 | 409.9 |
3 | 2017 | 4 | 摩根大通 | JPMorgan Chase | United States | 102.5 | 24.2 | 2513.0 | 306.6 |
4 | 2017 | 5 | 富国银行 | Wells Fargo | United States | 97.6 | 21.9 | 1943.4 | 274.4 |
# 添加空白列
df_2017['Company_cn_en'],df_2017['Country_cn_en'], df_2017['Country_cn'], df_2017['Industry_cn'], df_2017['Industry_en'] = ['','','','','']
# 按指定list重新将columns进行排序
# columns_sort = ['Year', 'Rank', 'Company_cn_en','Company_en',
# 'Company_cn', 'Country_cn_en', 'Country_cn',
# 'Country_en', 'Industry_cn', 'Industry_en',
# 'Sales', 'Profits', 'Assets', 'Market_value']
df_2017 = df_2017.reindex(columns=columns_sort)
print(df_2017.shape)
df_2017.head()
(2000, 14)
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2017 | 1 | ICBC | 中国工商银行 | China | 151.4 | 42.0 | 3473.2 | 229.8 | |||||
1 | 2017 | 2 | China Construction Bank | 中国建设银行 | China | 134.2 | 35.0 | 3016.6 | 200.5 | |||||
2 | 2017 | 3 | Berkshire Hathaway | 伯克希尔哈撒韦 | United States | 222.9 | 24.1 | 620.9 | 409.9 | |||||
3 | 2017 | 4 | JPMorgan Chase | 摩根大通 | United States | 102.5 | 24.2 | 2513.0 | 306.6 | |||||
4 | 2017 | 5 | Wells Fargo | 富国银行 | United States | 97.6 | 21.9 | 1943.4 | 274.4 |
# df_2017.to_csv('data_forbes_2017_update.csv')
df_concat = pd.concat([df_2007, df_2008, df_2009,
df_2010, df_2011, df_2012,
df_2013_all, df_2014,
df_2015, df_2016, df_2017], ignore_index=True)
df_concat
Year | Rank | Company_cn_en | Company_en | Company_cn | Country_cn_en | Country_cn | Country_en | Industry_cn | Industry_en | Sales | Profits | Assets | Market_value | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2007 | 1 | Citigroup /花旗集团 | Citigroup | 花旗集团 | 美国(US) | 美国 | US | 银行 | 146.560 | 21.540 | 1884.32 | 247.420 | |
1 | 2007 | 2 | Bank of America /美国银行 | Bank of America | 美国银行 | 美国(US) | 美国 | US | 银行 | 116.570 | 21.130 | 1459.74 | 226.610 | |
2 | 2007 | 3 | HSBC Holdings/汇丰集团 | HSBC Holdings | 汇丰集团 | 英国(UK) | 英国 | UK | 银行 | 121.510 | 16.630 | 1860.76 | 202.290 | |
3 | 2007 | 4 | General Electric /通用电气 | General Electric | 通用电气 | 美国(US) | 美国 | US | 多元化 | 163.390 | 20.830 | 697.24 | 358.980 | |
4 | 2007 | 5 | JPMorgan Chase /JP摩根大通 | JPMorgan Chase | JP摩根大通 | 美国(US) | 美国 | US | 银行 | 99.300 | 14.440 | 1351.52 | 170.970 | |
5 | 2007 | 6 | American Intl Group /美国国际集团 | American Intl Group | 美国国际集团 | 美国(US) | 美国 | US | 保险 | 113.190 | 14.010 | 979.41 | 174.470 | |
6 | 2007 | 7 | ExxonMobil /埃克森美孚 | ExxonMobil | 埃克森美孚 | 美国(US) | 美国 | US | 炼油 | 335.090 | 39.500 | 223.95 | 410.650 | |
7 | 2007 | 8 | Royal Dutch Shell /皇家荷兰壳牌集团 | Royal Dutch Shell | 皇家荷兰壳牌集团 | 荷兰(NL) | 荷兰 | NL | 炼油 | 318.850 | 25.440 | 232.31 | 208.250 | |
8 | 2007 | 9 | UBS /瑞士银行 | UBS | 瑞士银行 | 瑞士(SZ) | 瑞士 | SZ | 综合金融 | 105.590 | 9.780 | 1776.89 | 116.840 | |
9 | 2007 | 10 | ING Group /荷兰国际集团 | ING Group | 荷兰国际集团 | 荷兰(NL) | 荷兰 | NL | 保险 | 153.440 | 9.650 | 1615.05 | 93.990 | |
10 | 2007 | 11 | BP /英国石油 | BP | 英国石油 | 英国(UK) | 英国 | UK | 炼油 | 265.910 | 22.290 | 217.60 | 198.140 | |
11 | 2007 | 12 | Toyota Motor /丰田汽车 | Toyota Motor | 丰田汽车 | 日本(JA) | 日本 | JA | 耐用消费品 | 179.020 | 11.680 | 243.60 | 217.690 | |
12 | 2007 | 13 | Royal Bank of Scotland /苏格兰皇家银行 | Royal Bank of Scotland | 苏格兰皇家银行 | 英国(UK) | 英国 | UK | 银行 | 77.410 | 12.510 | 1705.35 | 124.130 | |
13 | 2007 | 14 | BNP Paribas /法国巴黎银行 | BNP Paribas | 法国巴黎银行 | 法国(FR) | 法国 | FR | 银行 | 89.160 | 9.640 | 1898.19 | 97.030 | |
14 | 2007 | 15 | Allianz /安联 | Allianz | 安联 | 德国(GE) | 德国 | GE | 保险 | 125.330 | 8.810 | 1380.88 | 87.220 | |
15 | 2007 | 16 | Berkshire Hathaway /伯克夏·哈萨威 | Berkshire Hathaway | 伯克夏·哈萨威 | 美国(US) | 美国 | US | 综合金融 | 98.540 | 11.020 | 248.44 | 163.790 | |
16 | 2007 | 17 | Wal-Mart Stores /沃尔玛 | Wal-Mart Stores | 沃尔玛 | 美国(US) | 美国 | US | 零售 | 348.650 | 11.290 | 151.19 | 201.360 | |
17 | 2007 | 18 | Barclays /巴克莱 | Barclays | 巴克莱 | 英国(UK) | 英国 | UK | 银行 | 67.710 | 8.950 | 1949.17 | 94.790 | |
18 | 2007 | 19 | Chevron /雪佛龙 | Chevron | 雪佛龙 | 美国(US) | 美国 | US | 炼油 | 195.340 | 17.140 | 132.63 | 149.370 | |
19 | 2007 | 19 | Total /道达尔菲纳埃尔夫 | Total | 道达尔菲纳埃尔夫 | 法国(FR) | 法国 | FR | 炼油 | 175.050 | 15.530 | 138.82 | 152.620 | |
20 | 2007 | 21 | HBOS /苏格兰哈里法克斯银行 | HBOS | 苏格兰哈里法克斯银行 | 英国(UK) | 英国 | UK | 银行 | 84.280 | 7.590 | 1156.61 | 79.830 | |
21 | 2007 | 22 | ConocoPhillips /大陆菲利普斯 | ConocoPhillips | 大陆菲利普斯 | 美国(US) | 美国 | US | 炼油 | 167.580 | 15.550 | 164.78 | 107.390 | |
22 | 2007 | 23 | AXA Group /安盛保险集团 | AXA Group | 安盛保险集团 | 法国(FR) | 法国 | FR | 保险 | 98.850 | 6.380 | 666.47 | 87.640 | |
23 | 2007 | 24 | Société Générale Group /法国兴业银行 | Société Générale Group | 法国兴业银行 | 法国(FR) | 法国 | FR | 银行 | 84.470 | 6.550 | 1259.32 | 77.620 | |
24 | 2007 | 25 | Goldman Sachs Group /高盛集团 | Goldman Sachs Group | 高盛集团 | 美国(US) | 美国 | US | 综合金融 | 69.350 | 9.540 | 838.20 | 83.310 | |
25 | 2007 | 25 | Morgan Stanley /摩根士丹利 | Morgan Stanley | 摩根士丹利 | 美国(US) | 美国 | US | 综合金融 | 76.550 | 7.470 | 1120.65 | 79.760 | |
26 | 2007 | 27 | Banco Santander /桑坦德银行 | Banco Santander | 桑坦德银行 | 西班牙(SP) | 西班牙 | SP | 银行 | 62.340 | 7.370 | 945.86 | 115.750 | |
27 | 2007 | 27 | Deutsche Bank /德意志银行 | Deutsche Bank | 德意志银行 | 德国(GE) | 德国 | GE | 综合金融 | 95.500 | 7.450 | 1485.58 | 65.150 | |
28 | 2007 | 29 | AT&T /美国电话电报公司 | AT&T | 美国电话电报公司 | 美国(US) | 美国 | US | 电信运营商 | 63.060 | 7.360 | 270.63 | 229.780 | |
29 | 2007 | 30 | Electricité de France /法国电力公司 | Electricité de France | 法国电力公司 | 法国(FR) | 法国 | FR | 公用事业 | 77.750 | 7.390 | 233.40 | 133.370 | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
21971 | 2017 | 1971 | Tian An China Investments | NaN | Hong Kong | 0.244 | 0.736 | 4.30 | 1.200 | |||||
21972 | 2017 | 1972 | HollyFrontier | NaN | United States | 10.600 | -0.261 | 9.60 | 4.700 | |||||
21973 | 2017 | 1973 | Dah Sing Financial Holdings | NaN | Hong Kong | 0.868 | 0.244 | 28.80 | 2.600 | |||||
21974 | 2017 | 1973 | Nanya Technology | NaN | Taiwan | 1.300 | 0.736 | 4.30 | 4.300 | |||||
21975 | 2017 | 1973 | Shanxi Taigang Stainless | NaN | China | 8.500 | -0.322 | 11.00 | 4.100 | |||||
21976 | 2017 | 1976 | First Horizon National | NaN | United States | 1.400 | 0.227 | 28.70 | 4.300 | |||||
21977 | 2017 | 1977 | Brother Industries | NaN | Japan | 6.000 | 0.408 | 5.80 | 5.200 | |||||
21978 | 2017 | 1977 | Chicago Bridge & Iron | NaN | Netherlands | 10.700 | -0.313 | 7.80 | 3.100 | |||||
21979 | 2017 | 1979 | Belle International Holdings | NaN | Hong Kong | 6.300 | 0.384 | 4.70 | 5.400 | |||||
21980 | 2017 | 1979 | F5 Networks | NaN | United States | 2.000 | 0.370 | 2.40 | 8.900 | |||||
21981 | 2017 | 1979 | Valspar | NaN | United States | 4.200 | 0.341 | 4.20 | 8.800 | |||||
21982 | 2017 | 1982 | DKSH Holding | NaN | Switzerland | 10.700 | 0.212 | 4.30 | 5.100 | |||||
21983 | 2017 | 1982 | Grupo Galicia | NaN | Argentina | 3.700 | 0.407 | 15.30 | 5.100 | |||||
21984 | 2017 | 1984 | Bank of Iwate | NaN | Japan | 0.427 | 0.097 | 28.30 | 0.721 | |||||
21985 | 2017 | 1984 | Konica Minolta Business Solutions | NaN | Japan | 8.900 | 0.280 | 8.80 | 4.300 | |||||
21986 | 2017 | 1986 | Synnex Technology Intl | NaN | Taiwan | 10.600 | 0.151 | 4.00 | 1.800 | |||||
21987 | 2017 | 1987 | Eurazeo | NaN | France | 3.400 | 0.575 | 10.90 | 4.500 | |||||
21988 | 2017 | 1988 | Bankunited | NaN | United States | 1.200 | 0.217 | 28.10 | 3.900 | |||||
21989 | 2017 | 1988 | Barry Callebaut | NaN | Switzerland | 6.800 | 0.221 | 5.80 | 7.300 | |||||
21990 | 2017 | 1988 | Inchcape | NaN | United Kingdom | 10.600 | 0.249 | 5.40 | 4.400 | |||||
21991 | 2017 | 1991 | Yamanashi Chuo Bank | NaN | Japan | 0.522 | 0.062 | 28.00 | 0.739 | |||||
21992 | 2017 | 1992 | Guangxi Guiguan Electric Power | NaN | China | 2.000 | 0.643 | 6.00 | 6.000 | |||||
21993 | 2017 | 1992 | Live Nation Entertainment | NaN | United States | 8.400 | -0.047 | 6.80 | 6.400 | |||||
21994 | 2017 | 1992 | Shaanxi Coal Industry | NaN | China | 3.800 | -0.024 | 13.60 | 9.000 | |||||
21995 | 2017 | 1995 | Aurubis | NaN | Germany | 10.600 | 0.249 | 4.50 | 3.100 | |||||
21996 | 2017 | 1996 | BEKB-BCBE | NaN | Switzerland | 0.555 | 0.131 | 27.90 | 1.700 | |||||
21997 | 2017 | 1996 | Fastighets Balder | NaN | Sweden | 0.630 | 0.639 | 10.20 | 3.800 | |||||
21998 | 2017 | 1998 | Akamai Technologies | NaN | United States | 2.300 | 0.316 | 4.40 | 10.100 | |||||
21999 | 2017 | 1998 | Oita Bank | NaN | Japan | 0.523 | 0.071 | 27.90 | 0.595 | |||||
22000 | 2017 | 1998 | Tech Mahindra | NaN | India | 4.200 | 0.469 | 3.60 | 6.700 |
22001 rows × 14 columns
# df_concat.to_csv('data_forbes_concat.csv')
print('the shape of DataFrame: ', df_concat.shape)
print(df_concat.dtypes)
the shape of DataFrame: (22001, 14) Year int64 Rank int64 Company_cn_en object Company_en object Company_cn object Country_cn_en object Country_cn object Country_en object Industry_cn object Industry_en object Sales float64 Profits float64 Assets float64 Market_value float64 dtype: object
df_concat.loc[df_concat['Country_en']=='', 'Country_en'] = df_concat.loc[df_concat['Country_en']=='', 'Country_cn']
# df_concat[df_concat['Year']==2011]
# df_concat.to_csv('data_forbes_concat-1.csv')
* 将国家名称统一成英文名称,这里主要用的是 replace()方法
list_origin = [']','AR', 'AS','AU', 'US', 'BE', 'BR', 'BS', 'BU', 'CA', 'CH', 'CI',
'CN-HK', 'CN-TA', 'CO', 'CZ', 'DE', 'EG', 'FI', 'FR', 'GE',
'GR', 'Hong Kong', 'Hong Kong/China', 'HU', 'IC', 'ID', 'IN', 'IR',
'IS','IT', 'JA', 'JO', 'KO','LI', 'LU', 'MX', 'NL', 'NO', 'NZ',
'PA', 'PE', 'PH', 'PK', 'PL', 'PO', 'RU', 'SI', 'SP', 'SU',
'SW', 'SZ', 'Taiwan', 'TH', 'TU', 'UK', 'VE', '阿根廷', '阿联酋',
'阿曼', '埃及', '爱尔兰', '奥地利', '澳大利亚', '巴基斯坦', '巴林',
'巴拿马', '巴西', '百慕大', '比利时', '波多黎各', '波兰', '丹麦',
'德国', '多哥', '俄罗斯', '法国', '菲律宾', '芬兰', '哥伦比亚',
'哈萨克斯坦', '海峡群岛', '韩国', '荷兰', '加拿大', '捷克共和国',
'卡塔尔', '开曼群岛', '科威特', '克罗地亚', '黎巴嫩', '利比里亚',
'列支敦士登', '列支敦斯登', '卢森堡', '马来西亚', '毛里求斯',
'美国', '秘鲁', '摩洛哥', '墨西哥', '南非', '尼日利亚', '挪威',
'葡萄牙', '日本', '瑞典', '瑞士', '塞浦路斯', '沙特$',
'沙特阿拉伯', '斯洛伐克', '泰国', '土耳其', '委内瑞拉', '西班牙',
'希腊', '新加坡', '新西兰', '匈牙利', '以色列', '意大利',
'印度$', '印度尼西亚', '印尼', '英国', '约旦', '越南', '智利',
'中国大陆', '中国台湾', '中国香港', 'CN$', '中国$', 'Netherlands']
list_replace = ['','Argentina', 'Austria','Australia', 'United States', 'Belgium',
'Brazil', 'Bahamas', 'Bermuda', 'Canada', 'Chile', 'Cayman Islands',
'China-HongKong', 'China-Taiwan', 'Colombia', 'Czech Republic',
'Denmark', 'Egypt', 'Finland', 'France', 'Germany', 'Greece', 'China-HongKong',
'China-HongKong', 'Hungary', 'Iceland', 'Indonesia', 'India', 'Ireland', 'Israel',
'Italy', 'Japan', 'Jordan', 'South Korea','Liberia', 'Luxembourg', 'Mexico',
'Netherland', 'Norway', 'New Zealand', 'Panama', 'Peru', 'Philippines',
'Pakistan', 'Poland', 'Portugal', 'Russia', 'Singapore', 'Spain',
'Saudi Arabia', 'Sweden', 'Switzerland', 'China-Taiwan',
'Thailand', 'Turkey', 'United Kingdom', 'Venezuela', 'Argentina',
'United Arab Emirates', 'Oman', 'Egypt', 'Ireland', 'Austria', 'Australia',
'Pakistan', 'Bahrain', 'Panama', 'Brazil', 'Bermuda', 'Belgium',
'Puerto Rico', 'Poland', 'Denmark', 'Germany', 'Togo', 'Russia',
'France', 'Philippines', 'Finland', 'Colombia', 'Kazakhstan',
'Channel Islands', 'South Korea', 'Netherland', 'Canada',
'Czech Republic', 'Qatar', 'Cayman Islands', 'Kuwait', 'Croatia', 'Lebanon',
'Liberia', 'Liechtenstein', 'Liechtenstein', 'Luxembourg', 'Malaysia',
'Mauritius', 'United States', 'Peru', 'Morocco', 'Mexico', 'South Africa',
'Nigeria', 'Norway', 'Portugal', 'Japan', 'Sweden', 'Switzerland', 'Cyprus',
'Saudi Arabia', 'Saudi Arabia', 'Slovakia', 'Thailand', 'Turkey', 'Venezuela',
'Spain', 'Greece', 'Singapore', 'New Zealand', 'Hungary', 'Israel', 'Italy',
'India', 'Indonesia', 'Indonesia', 'United Kingdom', 'Jordan', 'Vietnam',
'Chile', 'China', 'China-Taiwan', 'China-HongKong', 'China', 'China',
'Netherland']
df_concat['Country_en'] = df_concat['Country_en'].replace(list_origin,list_replace, regex=True)
# df_concat['Country_en'] = df_concat['Country_en'].replace(['CN','中国'],['China', 'China'], regex=True)
# df_concat.head()
# df_concat.to_csv('data_forbes_concat-2.csv')
# 进一步替换,包括一家公司属于多个国家的情况
# 注意这里没有 regex=True
df_concat['Country_en'] = df_concat['Country_en'].replace(['China-China-Taiwan',r'China-HongKong/China', r'Australia)/United Kingdom(United Kingdom',
r'Netherland)/United Kingdom(United Kingdom', r'Panama)/United Kingdom(United Kingdom',
r'SA)/United Kingdom(United Kingdom', r'United Kingdom)/Australia(SA', r'United Kingdom)/Netherland(Netherland',
r'United Kingdom)/South Africa(SA' , 'Netherland/United Kingdom', 'Panama/United Kingdom',
'Australia/United Kingdom'],
['China-Taiwan', 'China-HongKong', 'United Kingdom/Australia', 'United Kingdom/Netherland',
'United Kingdom/Panama', 'United Kingdom/Australia', 'United Kingdom/Australia',
'United Kingdom/Netherland', 'United Kingdom/South Africa', 'United Kingdom/Netherland',
'United Kingdom/Panama', 'United Kingdom/Australia'])
# df_concat.head()
# df_concat.to_csv('data_forbes_concat-3.csv')
处理这类特殊情况的思路与步骤为:
(a)将此类英文缩写用空白值替换,
(b)将空白值替换为当前样本的中文国家名称
(c)将中文国家名称替换为各自的英文国家名称
# 注意需要以 "$"结尾
df_concat['Country_en'] = df_concat['Country_en'].replace(['MA$','SA$'],['', ''], regex=True)
# df_concat[df_concat['Country_en']=='']
df_concat.loc[df_concat['Country_en']=='', 'Country_en'] = df_concat.loc[df_concat['Country_en']=='', 'Country_cn']
# df_concat.to_csv('data_forbes_concat-4.csv')
df_concat['Country_en'] = df_concat['Country_en'].replace(['澳大利亚','马来西亚', '摩洛哥', '南非'],
['Australia', 'Malaysia', 'Morocco', 'South Africa'])
df_concat.to_csv('data_forbes_concat.csv')