我有一个数据数据和一个拟合系数的数据表.我想计算每一行的拟合值.
dt = data.table(a = rep(c("x","y"), each = 5), b = rnorm(10), c = rnorm(10), d = rnorm(10))
coefs = data.table(a = c("x","y"), b = c(0, 1), d = c(2,3))
dt
# a b c d
# 1: x -0.25174915 -0.2130797 -0.67909764
# 2: x -0.35569766 0.6014930 0.35201386
# 3: x -0.31600957 0.4398968 -1.15475814
# 4: x -0.54113762 -2.3497952 0.64503654
# 5: x 0.11227873 0.0233775 -0.96891456
# 6: y 1.24077566 -1.2843439 1.98883516
# 7: y -0.23819626 0.9950835 -0.17279980
# 8: …Run Code Online (Sandbox Code Playgroud) 我从这里有情节加载项
https://appsource.microsoft.com/en-us/product/office/WA104379485?tab=Overview
它适用于示例链接。但是对于工作来说,在线上传我的数据肯定是不行的。是否可以使用plotly.offline.plot 嵌入我在python 中生成的本地html 文件?
或者如果有其他方法可以在 ppt 中嵌入图表,我也很乐意接受。
下面的代码是从plotly教程https://plot.ly/python/filled-area-plots/复制的,除了带有设置的行opacity。
然而,这不起作用。如何设置填充区域的不透明度?
import plotly.plotly as py
import plotly.graph_objs as go
# Add original data
x = ['Winter', 'Spring', 'Summer', 'Fall']
trace0 = dict(
x=x,
y=[40, 60, 40, 10],
hoverinfo='x+y',
mode='lines',
##########
opacity = 0.5,
##########
line=dict(width=0.5,
color='rgb(131, 90, 241)'),
stackgroup='one'
)
trace1 = dict(
x=x,
y=[20, 10, 10, 60],
hoverinfo='x+y',
mode='lines',
##########
opacity = 0.5,
##########
line=dict(width=0.5,
color='rgb(111, 231, 219)'),
stackgroup='one'
)
trace2 = dict(
x=x,
y=[40, 30, 50, 30],
hoverinfo='x+y',
mode='lines',
##########
opacity = 0.5, …Run Code Online (Sandbox Code Playgroud) 是否可以在 fread 中指定数字列的数据类型?命令如
prices = markets[, fread(paste(mkt, 'price.csv')), by = mkt]
如果价格数据在一个文件中是整数而在另一个文件中是浮点数,则会失败。
因此,我必须显式编写一个 for 循环并将数据类型转换为数字并连接结果,而不是干净的单行代码。
我可以让pandas cut/qcut函数返回bin端点或bin中点而不是bin标签字符串吗?
目前
pd.cut(pd.Series(np.arange(11)), bins = 5)
0 (-0.01, 2]
1 (-0.01, 2]
2 (-0.01, 2]
3 (2, 4]
4 (2, 4]
5 (4, 6]
6 (4, 6]
7 (6, 8]
8 (6, 8]
9 (8, 10]
10 (8, 10]
dtype: category
Run Code Online (Sandbox Code Playgroud)
与类别/字符串值.我想要的是
0 1.0
1 1.0
2 1.0
3 3.0
4 3.0
Run Code Online (Sandbox Code Playgroud)
具有表示箱的边缘或中点的数值.
我有一个带有一列时间戳"2000-01-01 12:00:00.123456"的csv文件.在数据表中处理它的推荐方法是什么?我需要处理分组,匹配/滚动连接与另一个表中的IDate列,时间序列绘图等.
IDateTime("2000-01-01 12:00:00.123456")
Error in if (any(neg)) res[neg] = paste("-", res[neg], sep = "") :
missing value where TRUE/FALSE needed
Run Code Online (Sandbox Code Playgroud)
我在可能的重复问题中看到了这个答案,其中Matthew建议手动将日期转换为整数.但那已经3岁了,我想知道现在是否有更好的方法?
简答:是的,看到接受的回复.
我有以下两个data.table.
stocks = data.table(Ticker = c('xx','xx','yy','yy'), Date = c(as.IDate("2000-01-01"), as.IDate("2000-01-02")), t = c(1.8, 3.5))
Ticker Date t
1: xx 2000-01-01 1.8
2: xx 2000-01-02 3.5
3: yy 2000-01-01 1.8
4: yy 2000-01-02 3.5
tt = data.table(Date = c(as.IDate("2000-01-01"), as.IDate("2000-01-02")), t0 = c(1,2), t1 = c(2,3), t2 = c(3,4), y0 = c(10, 20), y1 = c(-20, -30), y2 = c(33,44))
Date t0 t1 t2 y0 y1 y2
1: 2000-01-01 1 2 3 10 -20 33
2: 2000-01-02 2 …Run Code Online (Sandbox Code Playgroud) 在 python pptx 模块中,
p = frame.add_paragraph()
p.text = 'text1'
p = frame.add_paragraph()
p.text = 'text2'
Run Code Online (Sandbox Code Playgroud)
将生成
如何切换到编号列表?
谢谢。
我正在用Python编写一个国际象棋程序,我使用python-chess进行棋盘表示和移动生成等。它通常非常好并且具有非常有用的功能。
然而,由于它是纯Python,它现在是我的AI的瓶颈。Python长整型及其按位运算在模块中被广泛使用,例如
x = b & -b
b ^= x
if not x & 0xffffffff:
x >>= 32
r |= 32
Run Code Online (Sandbox Code Playgroud)
无论如何,有没有办法通过其他模块来加速Python中的这种操作?是否可以不用 C 或 Fortran 重写?我尝试了numba包,但它似乎无法编译python long int。
非常感谢。
> dt = data.table(A = rep(c('x','y'), each = 3), B = 1:6)
> dt
A B
1: x 1
2: x 2
3: x 3
4: y 4
5: y 5
6: y 6
Run Code Online (Sandbox Code Playgroud)
我想将 A 中每个组的数据分箱,即所需的输出应如下所示
A B desired
1: x 1 [1,2]
2: x 2 [1,2]
3: x 3 (2,3]
4: y 4 [4,5]
5: y 5 [4,5]
6: y 6 (5,6]
Run Code Online (Sandbox Code Playgroud)
但
> dt[, C := cut(B, 2, include.lowest = TRUE), by = A]
> dt
A …Run Code Online (Sandbox Code Playgroud) data.table ×5
r ×5
python ×4
plotly ×2
powerpoint ×2
binning ×1
datetime ×1
fread ×1
pandas ×1