我正在尝试将Excel文件读取到Pandas数据框中并绘制2列。 我的代码如下:
import numpy as np
import pandas as pd
from pylab import plt
plt.style.use('seaborn')
data1 = pd.read_excel('LogReturns_AAPL.xlsx')
data1[['Returns', 'log_returns']].cumsum().apply(np.exp).plot(figsize=(10, 6))
但是我一直收到此错误:
FileNotFoundError: [WinError 2] The system cannot find the file specified
<Figure size 720x432 with 1 Axes>
(很长)回溯的一部分如下:
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x0000022E1842F158> (for post_execute):
Traceback (most recent call last):
File "C:\Users\DELL\Anaconda3\lib\subprocess.py", line 395, in check_output
**kwargs).stdout
File "C:\Users\DELL\Anaconda3\lib\subprocess.py", line 472, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\DELL\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 143, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "C:\Users\DELL\Anaconda3\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\DELL\Anaconda3\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
请让我知道我应该做些什么。谢谢!
Edit1:以下是Python脚本pwd
的结果:
'C:\\Users\\DELL\\Desktop'
答案 0 :(得分:0)
我认为您的问题与文件路径有关。因此,请尝试此
df = pd.read_excel(r'C:/Users/DELL/Desktop/LogReturns_AAPL.xlsx')
这会将熊猫引导到绝对路径。可能正是您需要的。