我最近安装了 Python 和 Visual Studio Code。参加完入门课程后,我编写了一个基本脚本并在 Visual Studio Code 中运行它。就在那时,我注意到 Visual Studio 代码中的 Python 设置方式存在问题。问题:当我启动 Visual Studio Code 并打开 python 文件时,终端默认为“C:\Users\my_name\Documents Python”(这是存储我的 python 文件的文件夹)。据我了解,当你使用Python时,提示符应该是“>>>”。我能够运行我的脚本,但无法在终端中运行任何其他 Python 代码(即像 z = 5 这样简单的代码)。如果我输入“Python”,系统会提示我“>>>”,但无法再运行我的脚本。
我认为这是一个安装问题,所以我卸载并重新安装了 Python 和 Visual,但问题仍然存在。
我尝试在系统设置下将程序安装位置的Python文件路径添加到Windows环境中,并在重新安装Python时单击“添加到路径”,但这些解决方案似乎都不起作用。
当基本的 python 代码(即 z=5)似乎不起作用但脚本运行良好时,我收到以下错误消息:
PS C:\Users\my_name\Documents\Python 2> z=5
z=5 : The term 'z=5' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is …Run Code Online (Sandbox Code Playgroud) 我有存储为字符串的销售数据。我正在尝试转换为浮点数,以便可以聚合数据,但收到以下错误“ValueError:无法将字符串转换为浮点数:'收入'。
我还尝试替换美元符号和逗号,但类型仍然是字符串。
>>> df['revenue'] = df['revenue'].replace('$| ','')
>>> type('revenue')
<class 'str'>
Run Code Online (Sandbox Code Playgroud)
我也尝试了以下方法
pd.to_numeric(df.revenue)
Run Code Online (Sandbox Code Playgroud)
但这也给了我一个错误,说“ValueError:无法解析字符串“$1,557.97”
该数据还包含负数(即(45.22))的括号,我不确定如何转换。