我尝试在 Ubuntu 20.04 中安装python3-dev,出现以下错误:
$ sudo apt-get install python3-dev
The following packages have unmet dependencies:
python3-dev : Depends: python3.8-dev (>= 3.8.2-1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
Run Code Online (Sandbox Code Playgroud)
这表明我需要先安装python3.8-dev,所以我尝试安装该包,但失败并出现以下错误:
$ sudo apt-get install python3.8-dev
The following packages have unmet dependencies:
python3.8-dev : Depends: zlib1g-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
Run Code Online (Sandbox Code Playgroud)
我再次尝试安装软件包:zlib1g-dev,但也失败了: …
我有一个形状(4,3)的数据帧如下:
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: x = pd.DataFrame(np.random.randn(4, 3), index=np.arange(4))
In [4]: x
Out[4]:
0 1 2
0 0.959322 0.099360 1.116337
1 -0.211405 -2.563658 -0.561851
2 0.616312 -1.643927 -0.483673
3 0.235971 0.023823 1.146727
Run Code Online (Sandbox Code Playgroud)
我想将数据帧的每一列与numpy数组形状(4,)相乘:
In [9]: y = np.random.randn(4)
In [10]: y
Out[10]: array([-0.34125522, 1.21567883, -0.12909408, 0.64727577])
Run Code Online (Sandbox Code Playgroud)
在numpy中,以下广播技巧有效:
In [12]: x.values * y[:, None]
Out[12]:
array([[-0.32737369, -0.03390716, -0.38095588],
[-0.25700028, -3.11658448, -0.68303043],
[-0.07956223, 0.21222123, 0.06243928],
[ 0.15273815, 0.01541983, 0.74224861]])
Run Code Online (Sandbox Code Playgroud)
但是,它在pandas dataframe的情况下不起作用,我得到以下错误: …
我有一个数组如下:
In [1]: x = array(['1.2', '2.3', '1.2.3'])
Run Code Online (Sandbox Code Playgroud)
我想测试数组中的每个元素是否可以转换为数值。也就是说,函数:is_numeric(x)将返回True / False数组,如下所示:
In [2]: is_numeric(x)
Out[2]: array([True, True, False])
Run Code Online (Sandbox Code Playgroud)
这该怎么做?