What Idea about PE ROE CHART ?
In this article, we will explore the idea of using a Price-to-Earnings (PE) and Return on Equity (ROE) band chart to analyze financial data. We will use Python and some popular libraries to read and process the data, and then create a band chart to visualize it.
The code provided imports the necessary libraries, reads data from an Excel file, and stores it in a pandas DataFrame. It then sorts the DataFrame by market capitalization (MCap) and selects the top 50 companies.
Importing Libraries:
First, let’s import the necessary libraries:
import pandas as pd
import numpy as np
import plotly.express as px
Loading the Data:
Next, we will read the data from an Excel file hosted on Google Drive and store it in a pandas DataFrame:
path = 'https://drive.google.com/uc?expoert=download&id=1EqhMOcAPX7WfW1gObCPPsFq99D5RfA42'
df=pd.read_excel(path)
df
Name | No. | Links | Sign | Last | Chg% | Volume | Value (k) | MCap (M) | P/E | … | ROA% | ROE% | NPM% | Yield% | FFloat% | MG% | Magic1 | Magic2 | PEG | CG | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Average | NaN | NaN | NaN | 19.49 | 1.61 | 3.363165e+07 | 105048.26 | 24834.05 | 62.50 | … | 5.61 | 2.36 | -12.97 | 0.77 | 40.89 | NaN | 559.69 | 558.51 | -1.10 | NaN |
1 | 2S | 1.0 | i | 1 | 2 | 3 | NaN | 6.85 | 2.24 | 1.073600e+06 | 7281.00 | 3425.00 | 4.72 | … | 40.31 | 38.98 | 15.65 | 3.28 | 58.11 | NaN | 31.00 | 17.00 | 0.02 | NaN |
2 | 3K-BAT | 2.0 | i | NaN | 68.25 | -0.73 | 1.000000e+03 | 68.00 | 5351.00 | 49.35 | … | -3.08 | 5.28 | 3.29 | 0.37 | 2.10 | NaN | 914.00 | NaN | NaN | NaN |
3 | 7UP | 3.0 | i | 1 | 2 | 3 | NaN | 1.61 | 2.55 | 2.758150e+08 | 440191.00 | 8280.00 | 39.60 | … | 7.70 | 10.20 | 37.44 | NaN | 66.55 | NaN | 741.00 | 713.00 | -0.29 | NaN |
4 | A | 4.0 | i | 1 | 2 | 3 | NaN | 4.96 | -0.40 | 1.500000e+03 | 7.00 | 4861.00 | 51.30 | … | 3.99 | 2.77 | -4.93 | 0.60 | 25.86 | NaN | 989.00 | 927.00 | -0.18 | NaN |
… | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … |
752 | XPG | 752.0 | i | 1 | 2 | 3 | NaN | 3.98 | -4.33 | 3.193370e+07 | 128129.00 | 11405.00 | 830.92 | … | 1.49 | 1.56 | 129.78 | NaN | 61.26 | NaN | 1082.00 | 1106.00 | -1.65 | NaN |
753 | YGG | 753.0 | i | 1 | 3 | NaN | 20.70 | -1.90 | 6.996000e+05 | 14600.00 | 3726.00 | 43.20 | … | 22.08 | 24.21 | 32.10 | 0.85 | 26.32 | NaN | 534.00 | 489.00 | 2.63 | NaN |
754 | YUASA | 754.0 | i | 1 | 3 | NaN | 16.80 | 0.00 | 6.400000e+03 | 108.00 | 1808.00 | 10.59 | … | 16.70 | 20.39 | 5.82 | 2.63 | 15.27 | NaN | 215.00 | 178.00 | 0.23 | NaN |
755 | ZEN | 755.0 | i | 1 | 3 | NaN | 11.80 | -0.84 | 1.912000e+05 | 2278.00 | 3540.00 | 158.12 | … | 2.18 | 1.83 | -3.45 | 2.12 | 26.68 | NaN | 1060.00 | 1060.00 | -6.52 | NaN |
756 | ZIGA | 756.0 | i | 1 | 2 | 3 | NaN | 5.05 | -1.94 | 5.696200e+06 | 29052.00 | 2511.00 | 16.18 | … | 14.36 | 20.29 | 13.69 | 3.19 | 37.17 | NaN | 322.00 | 306.00 | 0.32 | NaN |
757 rows × 24 columns
Sorting by Market Capitalization:
We will now sort the DataFrame by the market capitalization (MCap) column in descending order and select the top 50 rows:
set50df = df.sort_values(['MCap (M)'],ascending=False)[:50]
set50df
Name | No. | Links | Sign | Last | Chg% | Volume | Value (k) | MCap (M) | P/E | … | ROA% | ROE% | NPM% | Yield% | FFloat% | MG% | Magic1 | Magic2 | PEG | CG | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
467 | PTT | 467.0 | i | 1 | 2 | 3 | NaN | 38.00 | -0.65 | 28381900.0 | 1074237.0 | 1085394.0 | 12.86 | … | 7.45 | 9.22 | 7.86 | 2.63 | 48.88 | NaN | 488.0 | 445.0 | 0.13 | NaN |
170 | DELTA | 170.0 | i | 1 | 2 | 3 | NaN | 764.00 | 4.66 | 3045800.0 | 2312848.0 | 953000.0 | 123.83 | … | 14.17 | 21.41 | 8.52 | 0.43 | 22.35 | NaN | 619.0 | 615.0 | -7.49 | NaN |
42 | AOT | 42.0 | i | 1 | 2 | 3 | NaN | 63.00 | -0.79 | 14060600.0 | 884765.0 | 899999.0 | NaN | … | -8.68 | -11.27 | -184.60 | 0.30 | 30.00 | NaN | NaN | NaN | NaN | NaN |
15 | ADVANC | 15.0 | i | 1 | 2 | 3 | NaN | 191.50 | 0.79 | 7256600.0 | 1383672.0 | 569507.0 | 21.41 | … | 10.41 | 36.45 | 15.30 | 3.61 | 36.22 | NaN | 319.0 | 474.0 | -4.20 | NaN |
147 | CPALL | 147.0 | i | 1 | 2 | 3 | NaN | 62.50 | -0.79 | 46574000.0 | 2904196.0 | 561444.0 | 46.16 | … | 5.50 | 13.70 | 1.84 | 1.44 | 57.50 | NaN | 674.0 | 851.0 | 3.42 | NaN |
513 | SCC | 513.0 | i | 1 | 2 | 3 | NaN | 424.00 | -0.93 | 906700.0 | 385150.0 | 508800.0 | 10.21 | … | 9.89 | 15.37 | 14.88 | 3.30 | 66.21 | NaN | 274.0 | 300.0 | -1.60 | NaN |
236 | GULF | 236.0 | i | 1 | 2 | 3 | NaN | 41.75 | -1.76 | 69909800.0 | 2960616.0 | 489859.0 | 84.69 | … | 5.61 | 12.46 | 17.21 | 0.91 | 26.23 | NaN | 746.0 | 887.0 | 3.41 | NaN |
468 | PTTEP | 468.0 | i | 1 | 2 | 3 | NaN | 108.50 | -1.36 | 4623500.0 | 503196.0 | 430743.0 | 15.24 | … | 8.21 | 7.61 | 17.03 | 3.92 | 34.69 | NaN | 575.0 | 457.0 | 2.02 | NaN |
82 | BDMS | 82.0 | i | 1 | 2 | 3 | NaN | 23.20 | -0.85 | 14042900.0 | 326426.0 | 368694.0 | 52.83 | … | 8.54 | 8.55 | 8.91 | 2.37 | 65.98 | NaN | 823.0 | 722.0 | 2.44 | NaN |
512 | SCB | 512.0 | i | 1 | 2 | 3 | XD | 104.00 | -1.89 | 3662300.0 | 381120.0 | 353146.0 | 12.40 | … | 1.70 | 6.91 | 25.34 | 2.21 | 76.61 | NaN | 549.0 | 705.0 | -3.38 | NaN |
409 | OR | 409.0 | i | NaN | 29.25 | 0.00 | 15964200.0 | 469812.0 | 351000.0 | 26.03 | … | 7.86 | 11.90 | 3.02 | 0.33 | 23.72 | NaN | 590.0 | 605.0 | NaN | NaN |
293 | KBANK | 293.0 | i | 1 | 3 | NaN | 122.00 | -0.41 | 8435400.0 | 1028314.0 | 289058.0 | 7.30 | … | 1.90 | 9.18 | 19.27 | 2.05 | 79.60 | NaN | 367.0 | 583.0 | -488.67 | NaN |
516 | SCGP | 516.0 | i | 1 | 3 | NaN | 67.00 | -2.19 | 27537900.0 | 1850632.0 | 287626.0 | 39.25 | … | 6.83 | 10.41 | 9.14 | 0.67 | 26.21 | NaN | 736.0 | 752.0 | NaN | NaN |
266 | INTUCH | 266.0 | i | 1 | 2 | 3 | NaN | 86.75 | 0.87 | 10442200.0 | 899883.0 | 278172.0 | 26.73 | … | 20.79 | 28.51 | 273.84 | 2.88 | 63.21 | NaN | 388.0 | 372.0 | -3.58 | NaN |
469 | PTTGC | 469.0 | i | 1 | 2 | 3 | XD | 60.00 | -2.44 | 14956500.0 | 905059.0 | 270531.0 | 6.37 | … | 10.47 | 14.36 | 14.68 | 1.67 | 54.32 | NaN | 221.0 | 209.0 | 2.70 | NaN |
337 | MAKRO | 337.0 | i | 1 | 3 | NaN | 52.50 | 0.00 | 18354500.0 | 963709.0 | 252000.0 | 37.12 | … | 12.93 | 31.35 | 2.71 | 1.90 | 6.92 | NaN | 469.0 | 548.0 | 9.34 | NaN |
183 | EA | 183.0 | i | 1 | 2 | 3 | NaN | 66.00 | -0.75 | 12536300.0 | 834329.0 | 246180.0 | 48.36 | … | 8.37 | 19.03 | 25.94 | 0.45 | 40.37 | NaN | 592.0 | 722.0 | 2.08 | NaN |
152 | CPN | 152.0 | i | 1 | 2 | 3 | NaN | 53.50 | 1.42 | 11157100.0 | 594783.0 | 240108.0 | 25.14 | … | 6.19 | 14.21 | 30.88 | 1.31 | 62.75 | NaN | 523.0 | 670.0 | 1.94 | NaN |
75 | BAY | 75.0 | i | 1 | 3 | NaN | 32.25 | 0.78 | 1782800.0 | 57438.0 | 237223.0 | 7.65 | … | 2.40 | 10.44 | 31.96 | 1.09 | 23.12 | NaN | 341.0 | 570.0 | 0.50 | NaN |
274 | IVL | 274.0 | i | 1 | 2 | 3 | NaN | 42.25 | -0.59 | 15631400.0 | 669683.0 | 237215.0 | 14.88 | … | 5.60 | 11.73 | 7.14 | 1.66 | 35.11 | NaN | 452.0 | 574.0 | 0.49 | NaN |
229 | GPSC | 229.0 | i | 1 | 2 | 3 | NaN | 82.75 | -0.60 | 7248700.0 | 603553.0 | 233333.0 | 28.01 | … | 5.59 | 8.13 | 12.38 | 1.81 | 24.75 | NaN | 718.0 | 744.0 | 1.31 | NaN |
148 | CPF | 148.0 | i | 1 | 2 | 3 | NaN | 26.50 | -1.85 | 28640900.0 | 762444.0 | 228198.0 | 8.72 | … | 8.70 | 12.97 | 5.63 | 3.79 | 45.49 | NaN | 290.0 | 305.0 | 0.61 | NaN |
76 | BBL | 76.0 | i | 1 | 2 | 3 | NaN | 114.00 | 0.00 | 6231000.0 | 708242.0 | 217608.0 | 11.05 | … | 1.45 | 4.35 | 20.92 | 2.19 | 98.53 | NaN | 596.0 | 688.0 | 8.44 | NaN |
157 | CRC | 157.0 | i | 1 | 3 | NaN | 34.25 | -0.72 | 3287000.0 | 112461.0 | 206562.0 | 112.43 | … | 1.80 | 3.26 | 0.03 | 1.17 | 53.11 | NaN | 1019.0 | 1064.0 | NaN | NaN |
243 | HMPRO | 243.0 | i | 1 | 2 | 3 | NaN | 14.00 | -0.71 | 13010600.0 | 182351.0 | 184117.0 | 32.30 | … | 13.25 | 27.54 | 8.52 | 2.14 | 40.83 | NaN | 456.0 | 515.0 | 2.09 | NaN |
310 | KTC | 310.0 | i | 1 | 2 | 3 | NaN | 66.75 | -1.11 | 10156500.0 | 680479.0 | 172104.0 | 29.17 | … | 10.78 | 26.35 | 31.04 | 1.32 | 40.45 | NaN | 444.0 | 558.0 | 1.01 | NaN |
360 | MINT | 360.0 | i | 1 | 2 | 3 | NaN | 32.00 | -1.54 | 7722300.0 | 246868.0 | 166369.0 | NaN | … | -4.94 | -35.79 | -42.07 | NaN | 61.42 | NaN | NaN | NaN | NaN | NaN |
309 | KTB | 309.0 | i | 1 | 2 | 3 | NaN | 11.10 | -0.89 | 10181300.0 | 113044.0 | 155134.0 | 8.57 | … | 1.46 | 5.31 | 23.07 | 2.48 | 44.93 | NaN | 506.0 | 628.0 | 2.73 | NaN |
93 | BJC | 93.0 | i | 1 | 2 | 3 | NaN | 35.00 | 0.72 | 2810500.0 | 97958.0 | 140273.0 | 33.24 | … | 3.22 | 3.74 | 2.97 | 2.23 | 25.57 | NaN | 896.0 | 890.0 | 1.19 | NaN |
67 | AWC | 67.0 | i | 1 | 3 | NaN | 4.24 | 0.47 | 23363400.0 | 98952.0 | 135680.0 | NaN | … | -0.79 | -2.55 | -37.92 | NaN | 24.97 | NaN | NaN | NaN | NaN | NaN |
116 | CBG | 116.0 | i | 1 | 2 | 3 | NaN | 133.00 | -1.12 | 6198500.0 | 829850.0 | 133000.0 | 37.19 | … | 25.30 | 37.12 | 18.12 | 1.80 | 28.85 | NaN | 456.0 | 444.0 | 1.36 | NaN |
371 | MTC | 371.0 | i | 1 | 2 | 3 | NaN | 61.50 | -0.81 | 3287600.0 | 203283.0 | 130380.0 | 24.15 | … | 11.03 | 26.43 | 34.10 | 0.60 | 32.12 | NaN | 381.0 | 486.0 | 0.46 | NaN |
85 | BEM | 85.0 | i | 1 | 2 | 3 | NaN | 8.50 | -0.58 | 37106500.0 | 315875.0 | 129923.0 | 68.89 | … | 3.87 | 5.09 | 8.55 | 1.18 | 54.02 | NaN | 953.0 | 960.0 | 3.02 | NaN |
110 | BTS | 110.0 | i | 1 | 2 | 3 | NaN | 9.35 | -0.53 | 30140700.0 | 282400.0 | 123076.0 | 22.31 | … | 5.47 | 9.87 | 15.06 | 3.32 | 59.67 | NaN | 610.0 | 691.0 | 2.39 | NaN |
88 | BGRIM | 88.0 | i | 1 | 2 | 3 | NaN | 45.00 | 0.00 | 9387300.0 | 422143.0 | 117311.0 | 43.53 | … | 6.21 | 9.76 | 10.54 | 1.00 | 36.01 | NaN | 772.0 | 803.0 | 6.80 | NaN |
686 | TRUE | 686.0 | i | 1 | 2 | 3 | NaN | 3.36 | -1.18 | 73249300.0 | 247376.0 | 112117.0 | NaN | … | 2.93 | -1.12 | -1.34 | 2.08 | 31.78 | NaN | NaN | NaN | NaN | NaN |
411 | OSP | 411.0 | i | 1 | 3 | NaN | 35.00 | 0.00 | 12505100.0 | 433992.0 | 105131.0 | 29.43 | … | 15.76 | 18.64 | 12.68 | 3.14 | 46.56 | NaN | 505.0 | 457.0 | 3.46 | NaN |
90 | BH | 90.0 | i | 1 | 2 | 3 | NaN | 132.00 | -1.86 | 1120300.0 | 148576.0 | 104885.0 | 150.18 | … | 3.77 | 3.86 | 5.37 | 2.42 | 49.02 | NaN | 1014.0 | 991.0 | 60.82 | NaN |
589 | STGT | 589.0 | i | NaN | 36.25 | 0.00 | 6267600.0 | 227332.0 | 103793.0 | 3.48 | … | 83.42 | 102.28 | 60.74 | 7.23 | 34.33 | NaN | 5.0 | 5.0 | NaN | NaN |
695 | TTB | 695.0 | i | 1 | 2 | 3 | NaN | 1.06 | -0.93 | 111503500.0 | 118292.0 | 102194.0 | 12.51 | … | 1.35 | 4.01 | 16.24 | 4.25 | 34.20 | NaN | 640.0 | 725.0 | -4.79 | NaN |
665 | TOP | 665.0 | i | 1 | 2 | 3 | NaN | 49.50 | 0.00 | 11298500.0 | 562364.0 | 100981.0 | 7.58 | … | 6.87 | 12.08 | 3.64 | 1.41 | 51.96 | NaN | 293.0 | 350.0 | -5.03 | NaN |
324 | LH | 324.0 | i | 1 | 2 | 3 | NaN | 8.15 | 0.00 | 19943300.0 | 162013.0 | 97390.0 | 11.99 | … | 8.46 | 16.35 | 21.55 | 6.13 | 69.40 | NaN | 308.0 | 393.0 | 1.86 | NaN |
226 | GLOBAL | 226.0 | i | 1 | 2 | 3 | NaN | 21.10 | -1.40 | 14780900.0 | 311305.0 | 97095.0 | 34.71 | … | 10.36 | 16.17 | 10.87 | 0.84 | 32.11 | NaN | 578.0 | 602.0 | 1.32 | NaN |
700 | TU | 700.0 | i | 1 | 2 | 3 | NaN | 20.20 | -0.98 | 24200700.0 | 488060.0 | 96391.0 | 12.28 | … | 7.16 | 14.38 | 6.34 | 3.56 | 60.55 | NaN | 341.0 | 442.0 | -3.26 | NaN |
190 | EGCO | 190.0 | i | 1 | 2 | 3 | NaN | 181.00 | 0.84 | 1185100.0 | 214379.0 | 95290.0 | 15.49 | … | 5.31 | 5.97 | 12.44 | 3.59 | 50.00 | NaN | 629.0 | 606.0 | 0.35 | NaN |
509 | SAWAD | 509.0 | i | 1 | 2 | 3 | NaN | 69.25 | -1.77 | 6545600.0 | 455449.0 | 95091.0 | 19.31 | … | 14.77 | 22.56 | 49.65 | 2.60 | 45.03 | NaN | 356.0 | 355.0 | 0.63 | NaN |
297 | KCE | 297.0 | i | 1 | 2 | 3 | NaN | 77.00 | -1.60 | 11156900.0 | 867800.0 | 90943.0 | 52.08 | … | 10.95 | 14.30 | 15.84 | 1.03 | 58.02 | NaN | 674.0 | 649.0 | -3.77 | NaN |
179 | DTAC | 179.0 | i | 1 | 2 | 3 | NaN | 38.00 | -1.30 | 8252800.0 | 316006.0 | 89977.0 | 23.13 | … | 4.66 | 17.57 | 5.79 | 7.87 | 29.26 | NaN | 443.0 | 727.0 | -0.15 | NaN |
639 | TIDLOR | 639.0 | i | 1 | 3 | NaN | 38.25 | -1.92 | 10047200.0 | 387333.0 | 88701.0 | 29.81 | … | 7.35 | 13.34 | 26.91 | NaN | 44.53 | NaN | 597.0 | 668.0 | NaN | NaN |
144 | COM7 | 144.0 | i | 1 | 2 | 3 | NaN | 71.50 | 2.51 | 13313100.0 | 941356.0 | 85800.0 | 40.80 | … | 25.05 | 61.83 | 4.90 | 1.40 | 45.71 | NaN | 459.0 | 470.0 | 0.90 | NaN |
50 rows × 24 columns
set50df.columns
Index(['Name', 'No.', 'Links', 'Sign', 'Last', 'Chg%', 'Volume', 'Value (k)','MCap (M)', 'P/E', 'P/BV', 'D/E', 'DPS', 'EPS', 'ROA%', 'ROE%', 'NPM%','Yield%', 'FFloat%', 'MG%', 'Magic1', 'Magic2', 'PEG', 'CG'],dtype='object')
set50df['Yield%']=set50df['Yield%'].astype(float)
# must be type float for plotly display
set50df.dtypes
Name object
No. float64
Links object
Sign object
Last float64
Chg% float64
Volume float64
Value (k) float64
MCap (M) float64
P/E float64
P/BV object
D/E float64
DPS object
EPS float64
ROA% float64
ROE% float64
NPM% float64
Yield% float64
FFloat% float64
MG% float64
Magic1 float64
Magic2 float64
PEG float64
CG float64
dtype: object
Creating the PE Band Chart:
With our data now sorted, we can create a PE band chart to visualize the relationship between the Price-to-Earnings ratio (P/E) and the Return on Equity (ROE). We will use the Plotly Express library to achieve this:
fig = px.scatter(set50df,x='ROE%',y='P/E',color='Yield%',text='Name',hover_data=['Name','PEG'],title='FUNDAMENTAL PE : ROE SET50')