代码中的名称用ai改成中文后运行不出来图片该怎么办啊?想用代码读取文档但一直错误,怎么把文档用进去啊?

import pandas as pd
import matplotlib.pyplot as plt

读取数据文件#

data = pd.read_excel (“财务报告.xlsx”)

提取年份和财务数据#

years = data [“年份(年)”]
net_profit = data [“净利润”]
operating_income = data [“营业收入”]
total_assets = data [“资产总额”]
total_liabilities = data [“负债总额”]
current_assets = data [“流动资产”]
current_liabilities = data [“流动负债”]
cash_and_cash_equivalents = data [“现金及现金等价物”]

计算关键财务比率#

net_profit_margin = net_profit / operating_income * 100
return_on_equity = net_profit / (total_assets - total_liabilities) * 100
debt_to_asset_ratio = total_liabilities / total_assets * 100
current_ratio = current_assets / current_liabilities
cash_ratio = cash_and_cash_equivalents / current_liabilities

绘制图表#

plt.figure(figsize=(12, 8))

净利润率#

plt.subplot(3, 2, 1)
plt.plot(years, net_profit_margin)
plt.xlabel (“年份”)
plt.ylabel (“净利润率”)
plt.title (“净利润率变化趋势”)

净资产收益率#

plt.subplot(3, 2, 2)
plt.plot(years, return_on_equity)
plt.xlabel (“年份”)
plt.ylabel (“净资产收益率”)
plt.title (“净资产收益率变化趋势”)

资产负债率#

plt.subplot(3, 2, 3)
plt.plot(years, debt_to_asset_ratio)
plt.xlabel (“年份”)
plt.ylabel (“资产负债率”)
plt.title (“资产负债率变化趋势”)

流动比率#

plt.subplot(3, 2, 4)
plt.plot(years, current_ratio)
plt.xlabel (“年份”)
plt.ylabel (“流动比率”)
plt.title (“流动比率变化趋势”)

现金比率#

plt.subplot(3, 2, 5)
plt.plot(years, cash_ratio)
plt.xlabel (“年份”)
plt.ylabel (“现金比率”)
plt.title (“现金比率变化趋势”)

调整布局#

plt.tight_layout()

显示图表#

plt.show()
运行结果

Jason990420
最佳答案

同样的问题,你为什么要重复问两个问题???

检查之后说的是没有找到 excel 文件

不是没有找到 excel 文件!是你没有提供要运行的 excel 文件给我们.

问题可能是因为发生在 A 栏位的 Column Name 是什么?"年份(年)",还是 "计价(千美元)", 所以要有你的 Excel 文件.

检查一下就知道了

>>> import pandas as pd
>>> data = pd.read_excel ("财务报告.xlsx")
>>> data.columns
Index(['年份(年)', '净利润', '营业收入', '资产总额', '负债总额', '流动资产', '流动负债', '现金及现金等价物'], dtype= 'object')

Python

9个月前 评论
Adoretheall123 (楼主) 9个月前
Adoretheall123 (楼主) 9个月前
讨论数量: 8
Jason990420
FileNotFoundError: [Errno 2] No such file or directory: '财务报告.xlsx'
9个月前 评论
Adoretheall123 (楼主) 9个月前
Lemon0818 9个月前
Jason990420 (作者) 9个月前

引号,ai 给改成了中文引号,代码是不允许中文引号的,应该把 “” 改成””

9个月前 评论
Jason990420

同样的问题,你为什么要重复问两个问题???

检查之后说的是没有找到 excel 文件

不是没有找到 excel 文件!是你没有提供要运行的 excel 文件给我们.

问题可能是因为发生在 A 栏位的 Column Name 是什么?"年份(年)",还是 "计价(千美元)", 所以要有你的 Excel 文件.

检查一下就知道了

>>> import pandas as pd
>>> data = pd.read_excel ("财务报告.xlsx")
>>> data.columns
Index(['年份(年)', '净利润', '营业收入', '资产总额', '负债总额', '流动资产', '流动负债', '现金及现金等价物'], dtype= 'object')

Python

9个月前 评论
Adoretheall123 (楼主) 9个月前
Adoretheall123 (楼主) 9个月前