我是 Python 新手,我正在尝试从一些简单的机器学习项目开始。我正在尝试将 sys、scipy、numpy、matplotlib、pandas 和 sklearn 包导入到 Visual Studio jupyter 笔记本中。我正在使用此测试代码来查看它们是否正确导入:
import sys
print('Python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__))
Run Code Online (Sandbox Code Playgroud)
当我在从 anaconda 启动的网站上使用 jupyter 笔记本执行此操作时,它没有给我带来任何问题。但是,我想使用 VS code,但是当我在那里运行它时,它给了我这个:
P5 C:\Users\matti> conda activate base
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling …Run Code Online (Sandbox Code Playgroud) 我正在 Windows 计算机中使用以下命令创建 conda env:
conda create -n s1 python=3.6
conda activate s1
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict
Run Code Online (Sandbox Code Playgroud)
然后,我安装geopandas, rasterio, jupyterlab软件包:
conda install geopandas
conda install jupyterlab
conda install raserio
Run Code Online (Sandbox Code Playgroud)
如果我从终端打开 python 并加载包:
(s1) C:\>python
Python 3.6.13 (default, Sep 7 2021, 06:39:02) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import geopandas
>>> import rasterio
Run Code Online (Sandbox Code Playgroud)
一切正常。但是,如果我打开jupyter lab:
(s1) C:\>jupyter lab …Run Code Online (Sandbox Code Playgroud) 这看起来相对简单,但我还没有找到可以回答我的问题的副本,或者具有所需功能的方法。
我有一个 Excel 电子表格,其中包含数据的每一列都有一个唯一的标题。我想通过pandas将此标题字符串传递给函数来获取列的字母键。
例如,如果我将“输出参数”传递给函数,我想返回“M”:
我发现的最接近的方法是将电子表格数字转换为列字母xlsxwriter.utility.xl_col_to_name(index)中的第二个答案中概述的方法
这与我想要做的非常相似,但是我的工作表中的列号不会保持不变(与标题不同,标题会保持不变)。话虽这么说,可以根据标题返回列号的方法也可以工作,因为这样我就可以应用上述内容。
有pandas或xlsxwriter有方法可以处理上述情况吗?
我尝试编写一个脚本,根据我对文件的命名,将文件从一个文件夹移动到一组文件夹。
例如,“Physics - a”将从“ts”文件夹移动到“/Physics/Assignments”,以便组织我的笔记。
它在后台持续运行,并在将某些内容放入“ts”文件夹时为这些文件分配新的位置。
我的脚本有效,但分配两个文件后,出现以下错误:
第 14 行,add = name.split('-') ValueError: 没有足够的值来解压(预期为 2,实际为 1)。
我不明白为什么会发生这种情况,也不明白如何解决它。
import os
import time
from datetime import date
def clean():
os.chdir('/Users/Chadd/Desktop/ts')
i = 0
while i < len(os.listdir()):
i = 0
name, ext = os.path.splitext(os.listdir()[i])
code, add = name.split('-')
folder = code.strip().upper()
if add.strip() == 'a':
add = 'Assignments'
if add.strip() == 'p':
add = 'Past Papers'
if add.strip() == 'n':
add = 'Notes'
if add.strip() == 't':
add = 'Tutorials'
today …Run Code Online (Sandbox Code Playgroud) 我使用 PyVista 创建了两个圆柱形网格,目的是使用 PyAnsys 在内圆柱体(以蓝色显示)和外圆柱体(以灰色显示)上执行模态分析。其中每个气缸具有不同的材料属性并构成单个模型的一部分:
网格生成脚本:
import numpy as np
import pyvista as pv
def create_mesh(inner_radius, thickness, height, z_res, c_res, r_res_pipe, r_res_fluid):
# Create a pipe mesh using a structured grid using the specified mesh density:
outer_radius = inner_radius + thickness
# Create a list of radial divisions between the inner and outer radii:
if r_res_pipe % 2 != 0:
r_res_pipe = r_res_pipe + 1 # radial resolution must be even to accommodate array reshaping
radial_divisions = np.linspace(inner_radius, …Run Code Online (Sandbox Code Playgroud)