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')