-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapple_analysis.py
More file actions
46 lines (39 loc) · 1.51 KB
/
Copy pathapple_analysis.py
File metadata and controls
46 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pandas as pd
import matplotlib.pyplot as plt
# 中文图表兼容
plt.rcParams["font.family"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
# 读取Excel,第一行作为表头
df = pd.read_excel(r"C:\Users\333\Desktop\apple_finance.xlsx", header=0)
# A列设为行索引(财务指标)
df = df.set_index(df.columns[0])
# 自动提取所有年份列,不用手动写日期字符串
years = df.columns.tolist()
print("表格所有年份:", years)
# 提取四大指标数据
revenue = df.loc["收入"].values
net_profit = df.loc["归母净利润"].values
gross_rate = df.loc["销售毛利率"].values
roe = df.loc["净资产收益率"].values
# 图1:营收、净利润
plt.figure(figsize=(10, 5))
plt.plot(years, revenue, marker="o", linewidth=2, label="年度营收(亿美元)")
plt.plot(years, net_profit, marker="s", linewidth=2, label="归母净利润(亿美元)")
plt.title("苹果2021-2025年营收与净利润走势")
plt.xticks(rotation=30)
plt.legend()
plt.grid(alpha=0.3)
plt.show()
# 图2:毛利率、ROE对比
plt.figure(figsize=(10, 5))
plt.plot(years, gross_rate, marker="o", label="销售毛利率")
plt.plot(years, roe / 10, marker="s", label="净资产收益率(÷10缩放)")
plt.title("苹果历年毛利率与净资产收益率变化")
plt.xticks(rotation=30)
plt.legend()
plt.grid(alpha=0.3)
plt.show()
# 输出数据
print("\n五年营收数据:", revenue)
print("五年归母净利润:", net_profit)
print("五年销售毛利率:", gross_rate)