我正试图找到笛卡尔积的dplyr函数.我有两个简单的data.frame,没有公共变量:
x <- data.frame(x=c("a","b","c"))
y <- data.frame(y=c(1,2,3))
Run Code Online (Sandbox Code Playgroud)
我想重现一下结果
merge(x,y)
x y
1 a 1
2 b 1
3 c 1
4 a 2
5 b 2
6 c 2
7 a 3
8 b 3
9 c 3
Run Code Online (Sandbox Code Playgroud)
非常感谢你
我试图用 ggplot2 用两组不同的点绘制一个区域,但我总是得到两个不同的图例。我读过这个和这个, 但我仍然有两个传说。下面是代码和图表。
非常感谢
library(ggplot2)
library(dplyr)
set.seed(1)
df <- data.frame(x = letters,
y = 1:26 +runif(26),
z = 2*(1:26) + runif(26),
jj = 1:26,
hh = 1:26*2,
x1 = 1:26)
some_names <- df %>%
filter(row_number() %% 10 == 1) %>%
select(x,x1)
p <- df %>%
ggplot(aes(x1)) +
geom_ribbon(aes(ymin = y, ymax = z, fill = "area")) +
geom_point(aes(y = jj, colour = "points1")) +
geom_point(aes(y = hh, colour = "points2")) +
scale_x_continuous(breaks = some_names %>% select(x1) …Run Code Online (Sandbox Code Playgroud) 我想使用 dask 2.14 扩展我在 Pandas 数据帧上执行的一些操作。例如,我想对数据框的列应用移位:
import dask.dataframe as dd
data = dd.read_csv('some_file.csv')
data.set_index('column_A')
data['column_B'] = data.groupby(['column_A'])['column_B'].shift(-1)
Run Code Online (Sandbox Code Playgroud)
但是我AttributeError: 'SeriesGroupBy' object has no attribute 'shift'
读了 dask 文档,发现没有这样的方法(而在熊猫中)
你能提出一些有效的替代方案吗?
谢谢
我对 Julia 很陌生,我正在尝试转换数组中的元组向量。这是一个例子
using Statistics
a = randn((10, 100))
q = (0.05, 0.95)
conf_intervals = [quantile(a[i,:], q) for i in 1:10]
Run Code Online (Sandbox Code Playgroud)
并且conf_intervals是一个10-element Vector{Tuple{Float64, Float64}}。
预期的结果应该是 10×2 Matrix{Float64}
我试过conf_intervals用,[conf_intervals...]但向量没有改变。
非常感谢
我有 VS code 1.56,我正在尝试运行 python 和 julia。我在交互式窗口中运行选定的 python 代码时遇到一些问题。当我按下按键绑定(shift + Enter)时,我没有得到任何操作。我尝试“切换键盘快捷键故障排除”,并收到以下日志
[2021-05-11 14:08:54.305] [renderer1] [info] [KeybindingService]: \ From 13 keybinding entries, matched jupyter.execSelectionInteractive, when: editorTextFocus && jupyter.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python', source: user extension ms-toolsai.jupyter.
[2021-05-11 14:08:54.308] [renderer1] [error] spawn python ENOENT: Error: spawn python ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Run Code Online (Sandbox Code Playgroud)
我在这里阅读标记“Jupyter:将选择发送到交互式窗口”,但仍然不起作用。
你有什么建议吗?
我有一个 NumPy 数组,其元素是字符串。例如
import numpy as np
a = np.array(["abcde", "degag"])
Run Code Online (Sandbox Code Playgroud)
我需要从数组的每个元素(substr/strleft)中提取前 n 个字符。前 3 个字符的结果应该是一个如下所示的数组:
array(['abc', 'deg'], dtype='<U3')
Run Code Online (Sandbox Code Playgroud)
非常感谢
我必须导入一个类似于以下数据框的表:
> df = data.frame(x = c("a", "a.b","a.b.c","a.b.d", "a.d"))
> df
x
1 <NA>
2 a
3 a.b
4 a.b.c
5 a.b.d
6 a.d
Run Code Online (Sandbox Code Playgroud)
我想根据我会找到多少个分隔符将第一列分隔在一列或多列中。
输出应该像这样
> df_separated
col1 col2 col3
1 a <NA> <NA>
2 a b <NA>
3 a b c
4 a b d
5 a d <NA>
Run Code Online (Sandbox Code Playgroud)
我尝试在 tidyr 中使用单独的函数,但我需要先验地指定我需要多少输出列。
非常感谢您的帮助
r ×3
arrays ×1
dask ×1
data-import ×1
dplyr ×1
ggplot2 ×1
julia ×1
key-bindings ×1
legend ×1
numpy ×1
python ×1
python-3.x ×1
string ×1
tidyr ×1
tidyverse ×1