我对VS Code和Python相当陌生。基本上,我试图在Windows 10计算机上的VS Code中运行以下代码行。
import pandas as pd
df = pd.DataFrame ({'x':range(-10,11)})
df['y'] = (3*df['x']-4)/2
df
我设法在python命令提示符下成功完成此操作。请参考以下结果。
(env2) C:\Users\Benjamin Chen\Desktop\Python Codes\python_env\env2\Scripts>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> df = pd.DataFrame ({'x':range(-10,11)})
>>> df['y'] = (3*df['x']-4)/2
>>> df
x y
0 -10 -17.0
1 -9 -15.5
2 -8 -14.0
3 -7 -12.5
4 -6 -11.0
5 -5 -9.5
6 -4 -8.0
7 -3 -6.5
8 -2 -5.0
9 -1 -3.5
10 0 -2.0
11 1 -0.5
12 2 1.0
13 3 2.5
14 4 4.0
15 5 5.5
16 6 7.0
17 7 8.5
18 8 10.0
19 9 11.5
20 10 13.0
>>>
但是我很难在VS Code上产生相同的结果。请参阅下面我从VS Code端子获得的输出。
(env2) PS C:\Users\Benjamin Chen\Desktop\Python Codes> & "C:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/Scripts/python.exe" "c:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/math.py"
(env2) PS C:\Users\Benjamin Chen\Desktop\Python Codes> & "C:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/Scripts/python.exe" "c:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/math.py"
(env2) PS C:\Users\Benjamin Chen\Desktop\Python Codes> & "C:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/Scripts/python.exe" "c:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/math.py"
(env2) PS C:\Users\Benjamin Chen\Desktop\Python Codes> & "C:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/Scripts/python.exe" "c:/Users/Benjamin Chen/Desktop/Python Codes/python_env/env2/math.py"
(env2) PS C:\Users\Benjamin Chen\Desktop\Python Codes>
我的Python版本是3.8.1。并且我已经在我的环境中的软件包下面安装了
Package Version
--------------- -------
cycler 0.10.0
kiwisolver 1.1.0
matplotlib 3.1.2
numpy 1.18.0
pandas 0.25.3
pip 19.3.1
pyparsing 2.4.6
python-dateutil 2.8.1
pytz 2019.3
setuptools 41.2.0
six 1.13.0
关于在VS Code上产生相同结果的方法,能否请您指明正确的方向?非常感谢!