我不确定这些数据是否正确采用宽格式,但我想做的是以下内容:
从 形状 转换d1为 形状d2
In [26]: d1 = pd.DataFrame({'where':['x','y'],
...: 'p1':[3,7],
...: 'p2':[11,12]})
In [27]: d2=pd.DataFrame({
...: 'where':['x','x','y','y'],
...: 'who':['p1','p2','p1','p2'],
...: 'value':[3,11,7,12]})
Run Code Online (Sandbox Code Playgroud)
看起来像:
In [10]: d1
Out[10]:
where p1 p2
0 x 3 11
1 y 7 12
In [11]: d2
Out[11]:
where who value
0 x p1 3
1 x p2 11
2 y p1 7
3 y p2 12
Run Code Online (Sandbox Code Playgroud)
我认为这是某种形式d1.pivot( ... ),但我似乎不知道如何去做。
因此,需要明确的是,我希望能够将数据重塑d1为使用 pandas 的结构d2。
以下方法有效,但这是一个很糟糕的方法
d3 …Run Code Online (Sandbox Code Playgroud) 我有一个使用 R 3.6 的项目,我已将 R 升级到 4.0.2,并且想在该项目中使用 4.0.2。我想知道如何去做,或者我应该完全删除renv/并重建?
我做了以下事情:
> renv::init()
This project already has a lockfile. What would you like to do?
1: Restore the project from the lockfile.
2: Discard the lockfile and re-initialize the project.
3: Activate the project without snapshotting or installing any packages.
4: Abort project initialization.
Run Code Online (Sandbox Code Playgroud)
而且2从上面的选择来看,这似乎也是合理的。
给出如下内容:
import importlib
module_path = "mod"
mod = importlib.import_module(module_path, package=None)
print(mod.Foo.Bar.x)
Run Code Online (Sandbox Code Playgroud)
哪里mod.py:
class Foo:
class Bar:
x = 1
Run Code Online (Sandbox Code Playgroud)
mypy file.py --strict 引发以下错误:
file.py:7: error: Module has no attribute "Foo" [attr-defined]
Run Code Online (Sandbox Code Playgroud)
我想知道应该如何进行类型提示,或者这是否是通常会被忽略的东西# type: ignore[attr-defined] (假设代码是必要的,并且唯一的选项是类型提示或忽略类型提示)?
importlib在这种情况下使用使用的方式importlib是有一些路径:
x.y.<changes>.z
Run Code Online (Sandbox Code Playgroud)
哪里<changes>是动态的,其他的都是固定的。我确信该模块将包含正在调用的属性,但由于<changes>,importlib用于导入。
可以概括为:
我不确切地知道我将导入哪个模块,但我知道它将有一个
Foo类。
我跟着一个小教程,让我靠近我想要的地方,但它不是那里,我不知道如何用它做下一步.
这是'我目前的数字:

我不知道如何将渐近线绘制到此图中.
我想我需要创建一个名为Y垂直线的变量,然后绘制出那条线?我不确定这是否正确
在这种情况下,我如何为渐近线创建线?
编辑
import pylab as pl
import numpy as np
import matplotlib.pyplot as plt
"""
This is all from the tutorial located at :
http://scipy-lectures.github.io/intro/matplotlib/matplotlib.html
"""
pl.figure(figsize=(10, 6), dpi=80)
pl.subplot(1, 1, 1)
X = np.linspace(-5, 5, 500, endpoint=True)
C = (1/X**2)-5
P = X - X - 0.1
pl.xlim(X.min() * 1.1, X.max() * 1.1)
pl.ylim(C.min() * 1.1, C.max() * 1.1)
"""
Alters the position of the axis - moves them to the centre …Run Code Online (Sandbox Code Playgroud) 基本问题,ggplot似乎没有做我期望的事情.
ggplot(data=data.frame( x=c(-1,2),y=c(-1,2) ), aes(x=x,y=y)) +
geom_blank() +
geom_abline(slope = -1 , intercept = 1)
Run Code Online (Sandbox Code Playgroud)
我期待这个情节:
它正在密谋:
给出以下代码:
fig, ax = plt.subplots()
ax.scatter([1, 2, 3, 4, 5], [34, 22, 11, 4, 6], s=100)
_ = ax.text(x=0, y=1.1, s="This is some text", transform=ax.transAxes, fontsize=20)
rect = mpl.patches.Rectangle(
(0.5, 0.5), width=0.05, height=0.05, color="red", transform=ax.transAxes,
)
ax.add_patch(rect)
Run Code Online (Sandbox Code Playgroud)
这会创建:
我想将补丁添加到以下位置:
使情节如下所示:
不过,我似乎无法在轴脊区域之外添加补丁,例如以下代码:
fig, ax = plt.subplots()
ax.scatter([1, 2, 3, 4, 5], [34, 22, 11, 4, 6], s=100)
_ = ax.text(x=0, y=1.1, s="This is some text", transform=ax.transAxes, fontsize=20)
rect = mpl.patches.Rectangle(
(0.5, 0.5), width=0.05, height=0.5, color="red", transform=ax.transAxes,
)
ax.add_patch(rect)
Run Code Online (Sandbox Code Playgroud)
给出
在方法中查找matplotlib.figure.Figure …
使用时subprocess.run建议使用check = True(https://pycodequ.al/docs/pylint-messages/w1510-subprocess-run-check.html)。但是,我可能想在需要非零退出代码的地方运行一个子进程,我想知道是否有一种方法可以同时满足 pylint 和我的代码。
例如:
subprocess.run('ls | grep sdfjosidjf', shell = True, check = True)
Run Code Online (Sandbox Code Playgroud)
将(最有可能)提高:
CalledProcessError: Command 'ls | grep sdfjosidjf' returned non-zero exit status 1.
Run Code Online (Sandbox Code Playgroud)
如果这正是我所期待甚至想要的怎么办?
我可以删除check = True并禁用这一行的 pylint,我想知道是否有比这更通用的方法check = True,也许我期待0或1作为退出代码。
这是一个最小的工作示例:
nat <- structure(list(X = 1:336, value = c(56, 52, 48, 44, 43, 44, 37,
36, 29, 27, 15, 22, 36, 22, 59, 53, 49, 45, 44, 44, 38, 37, 30,
27, 16, 22, 35, 21, 61.1, 54.6, 49.9, 46.6, 45.6, 45, 39.7, 37.7,
30.7, 28.6, 15.9, 22.7, 37.7, 22, 59.6, 52, 47.9, 44.8, 43.5,
43.4, 38, 36.5, 29.5, 27.4, 15, 21.6, 36.7, 21.4, 59.4, 52.5,
48.4, 45.1, 44, 44.2, 38.5, 37.3, 30, 27.9, 15.3, 22.1, 36.8,
22.5, 59.7, 53, …Run Code Online (Sandbox Code Playgroud) 我知道我可以time用作
time <some command>
Run Code Online (Sandbox Code Playgroud)
但这需要我记住time之前输入<some command>
我想知道是否可以创建某种钩子,以便time为每个命令运行该钩子,但仅在我输入last-time或在 cli 中输入某些内容时才显示。
一个示例用法可能是:
$ sleep 2
$ last-time
________________________________________________________
Executed in 2.00 secs fish external
usr time 2.28 millis 912.00 micros 1.37 millis
sys time 0.30 millis 296.00 micros 0.00 millis
Run Code Online (Sandbox Code Playgroud) python ×6
matplotlib ×3
r ×3
ggplot2 ×2
plot ×2
dataframe ×1
fish ×1
mypy ×1
pandas ×1
pylint ×1
python-3.x ×1
renv ×1
subprocess ×1
sympy ×1
time ×1
time-series ×1
type-hinting ×1
version ×1
virtualenv ×1