使用pip更新包的方法是什么?那些不起作用
pip update
pip upgrade
Run Code Online (Sandbox Code Playgroud)
我知道这是一个简单的问题,但因为它不容易找到(pip 文档没有弹出,堆栈溢出的问题是相关的,但并不完全相关)
我读了我的数据
import pandas as pd
df = pd.read_csv('/path/file.tsv', header=0, delimiter='\t')
print df
Run Code Online (Sandbox Code Playgroud)
得到:
id text
0 361.273 text1...
1 374.350 text2...
2 374.350 text3...
Run Code Online (Sandbox Code Playgroud)
如何id从上面的数据框中删除列?我尝试了以下方法:
import pandas as pd
df = pd.read_csv('/path/file.tsv', header=0, delimiter='\t')
print df.drop('id', 1)
Run Code Online (Sandbox Code Playgroud)
但它引发了这个例外:
ValueError: labels ['id'] not contained in axis
Run Code Online (Sandbox Code Playgroud) 我认为我的问题应该很简单,但我无法在互联网上找到任何帮助.我是Python的新手,所以我可能会遗漏一些非常明显的东西.
我有一个数组,S,就像这样[x x x] (one-dimensional).我现在创建一个对角矩阵,sigma与np.diag(S)-到目前为止,那么好.现在,我想调整这个新的对角线数组的大小,以便我可以将它乘以我拥有的另一个数组.
import numpy as np
...
shape = np.shape((6, 6)) #This will be some pre-determined size
sigma = np.diag(S) #diagonalise the matrix - this works
my_sigma = sigma.resize(shape) #Resize the matrix and fill with zeros - returns "None" - why?
Run Code Online (Sandbox Code Playgroud)
但是,当我打印出内容时my_sigma,我明白了"None".有人可以指出我正确的方向,因为我无法想象这应该是如此复杂.
在此先感谢您的帮助!
卡斯帕
图形:
我有这个:
[x x x]
Run Code Online (Sandbox Code Playgroud)
我要这个:
[x 0 0]
[0 x 0]
[0 0 x]
[0 0 0]
[0 0 0]
[0 0 …Run Code Online (Sandbox Code Playgroud) 安装(ubuntu)python3.9后,安装一些pip包失败:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 14, in <module>
from setuptools.dist import Distribution, Feature
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 24, in <module>
from setuptools.depends import Require
File "/usr/lib/python3/dist-packages/setuptools/depends.py", line 7, in <module>
from .py33compat import Bytecode
File "/usr/lib/python3/dist-packages/setuptools/py33compat.py", line 54, in <module>
unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
AttributeError: 'HTMLParser' object has no attribute 'unescape'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Run Code Online (Sandbox Code Playgroud) 我安装了某个版本的软件包(例如 Transformers 3.4.0),我想安装较早的版本。我安装:
pip install transformers==3.1.0
Run Code Online (Sandbox Code Playgroud)
检查安装版本时
pip freeze
Run Code Online (Sandbox Code Playgroud)
我看到版本没有改变。
我有一个集合列表,我希望对 n 个不同的样本进行采样,每个样本都包含每个集合中的一个项目。我不想要的是按顺序排列,因此,例如,我将从第一组中获取所有样本,其中必须包含相同的项目。我也不想创建所有笛卡尔积,因为这在效率方面可能是不可能的......知道如何去做吗?或者甚至可以近似这种行为?
不起作用的示例:
(prod for i, prod in zip(range(n), itertools.product(*list_of_sets)))
Run Code Online (Sandbox Code Playgroud)