我在jsp下面有代码来创建一个dataTable.我使用bProcessing为true,显示"处理"指示器,直到我从服务器获取数据.我想将消息显示为"正在加载数据.."而不是"处理".我尝试在各种网站上建议使用sProcessing但它不起作用?
customersTable = $('cutomer').dataTable({
"sAjaxSource": "ajax url",
"bProcessing":true,
"bDeferRender": true,
"sServerMethod": "POST",
"oLanguage": {
"sProcessing": "loading data..."
}
});
Run Code Online (Sandbox Code Playgroud) 这个问题适合理解 group_by 函数的正确功能。
假设我有一个包含 5 个二进制变量(这些变量的含义并不重要)和一个变量 id 代表一些用户的数据框。例如:
id<- c("A","A" , "B" , "B")
d<- as.data.frame(id)
d$d1<- c(1,0,1,0)
d$d2<- c(1,0,1,0)
d$d3<- c(0,1,1,0)
d$d4<- c(0,1,0,1)
d$d5<- c(0,1,0,0)
> d
id d1 d2 d3 d4 d5
1 A 1 1 0 0 0
2 A 0 0 1 1 1
3 B 1 1 1 0 0
4 B 0 0 0 1 0
Run Code Online (Sandbox Code Playgroud)
我将构建一个函数来检查每个用户 A 和 B,变量 d1 到 d5 都包含 1。
verificator<- function(d )
{
r<- prod(apply(d[,2:6],2, sum))
r<- as.logical(r) …Run Code Online (Sandbox Code Playgroud) 我有两个数据框
df1 = pd.DataFrame({'A': ['A1', 'A1', 'A2', 'A3'],
'B': ['121', '345', '123', '146'],
'C': ['K0', 'K1', 'K0', 'K1']})
df2 = pd.DataFrame({'A': ['A1', 'A3'],
'BB': ['B0', 'B3'],
'CC': ['121', '345'],
'DD': ['D0', 'D1']})
Run Code Online (Sandbox Code Playgroud)
现在我需要从df1的A列和B列以及从df2的A列和CC列获得相似的行。因此,我尝试了可能的合并选项,例如:
both_DFS=pd.merge(df1,df2, how='left',left_on=['A','B'],right_on=['A','CC'])
Run Code Online (Sandbox Code Playgroud)
这不会给我来自df2数据帧的行信息,这是我所需要的。意思是,我拥有df2中的所有列名,但行只是空或Nan。
然后我尝试:
Both_DFs=pd.merge(df1,df2, how='left',left_on=['A','B'],right_on=['A','CC'])[['A','B','CC']]
Run Code Online (Sandbox Code Playgroud)
这给了我错误,
KeyError: "['B'] not in index"
Run Code Online (Sandbox Code Playgroud)
我的目标是将df1和df2中的所有列都合并到Dataframe中。任何建议都很好
所需的输出:
Both_DFs
A B C BB CC DD
0 A1 121 K0 B0 121 D0
Run Code Online (Sandbox Code Playgroud)
因此,在我的数据帧(df1和df2)中,只有一行与目标两列都完全匹配。也就是说,df1中的A和B列只有一行与df2中A和CC列中的行完全匹配
我想在pandas数据框列中找到一个特定的模式,并返回相应的索引值以对数据框进行子集化。
这是带有可能模式的示例数据框:
生成数据框的代码段:
import pandas as pd
import numpy as np
Observations = 10
Columns = 2
np.random.seed(123)
df = pd.DataFrame(np.random.randint(90,110,size=(Observations, Columns)),
columns = ['ColA','ColB'])
datelist = pd.date_range(pd.datetime(2017, 7, 7).strftime('%Y-%m-%d'),
periods=Observations).tolist()
df['Dates'] = datelist
df = df.set_index(['Dates'])
pattern = [100,90,105]
print(df)
Run Code Online (Sandbox Code Playgroud)
数据框:
ColA ColB
Dates
2017-07-07 103 92
2017-07-08 92 96
2017-07-09 107 109
2017-07-10 100 91
2017-07-11 90 107
2017-07-12 105 99
2017-07-13 90 104
2017-07-14 90 105
2017-07-15 109 104
2017-07-16 94 90
Run Code Online (Sandbox Code Playgroud)
下面,感兴趣的格局发生Column A的日期2017-07-10 …
在JupyterLab和Jupyter Notebook中,您都可以使用ctrl + Enter以下命令执行单元:
码:
print('line 1')
print('line 2')
print('line 3')
Run Code Online (Sandbox Code Playgroud)
单元格和输出:
但是,你怎么能运行只 line 2?甚至在不运行整个单元的情况下选择单元中的线?当然,您可以只插入带有单行或选择的行的单元格,但这确实非常麻烦并且很快。那么,有没有更好的方法可以做到这一点?
我已经实现了简单的代码来gradient boosting regression (GBR)预测one output并且效果很好,但是当我尝试预测时two outputs出现错误,如下所示:
ValueError Traceback (most recent call last)
<ipython-input-5-bb1f191ee195> in <module>()
4 }
5 gradient_boosting_regressor = ensemble.GradientBoostingRegressor(**params)
----> 6 gradient_boosting_regressor.fit(train_data,train_targets)
7 # 'learning_rate': 0.01
D:\Anoconda\lib\site-packages\sklearn\ensemble\gradient_boosting.py in fit(self, X, y, sample_weight, monitor)
977
978 # Check input
--> 979 X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'], dtype=DTYPE)
980 n_samples, self.n_features_ = X.shape
981 if sample_weight is None:
D:\Anoconda\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, …Run Code Online (Sandbox Code Playgroud) 不确定我是否在这里遗漏了一些明显的东西,但是当我在带有注释的文本中插入一个中断(<br>)时,它似乎忽略了它。我已经尝试过fig.add_annotations,但同样的事情发生了。
你知道为什么这不起作用吗?
import pandas as pd
import plotly.graph_objects as go
import numpy as np
df = pd.DataFrame({"Growth_Type": ["Growing Fast", "Growing", "Stable", "Dropping", "Dropping Fast"],
"Accounts": [407,1275,3785,1467,623],
"Gain_Share": [1.20,8.1,34.4,6.5,0.4],
"Keep_Share": [16.5, 101.2, 306.3, 107.2, 27.7]})
df2 = pd.concat([pd.DataFrame({"Growth_Type":df["Growth_Type"],
"Opportunity_Type": np.repeat("Gain Share", 5),
"Wallet_Share": df["Gain_Share"]}),
pd.DataFrame({"Growth_Type":df["Growth_Type"],
"Opportunity_Type": np.repeat("Keep Share", 5),
"Wallet_Share": df["Keep_Share"]})])
fig = go.Figure()
fig.add_trace(go.Bar(x = df2["Wallet_Share"],
y = df2["Growth_Type"],
orientation = "h"
))
fig.update_layout(font = dict(size = 12, color = "#A6ACAF"),
xaxis_tickprefix = "$",
plot_bgcolor …Run Code Online (Sandbox Code Playgroud) 我有一个 3D 散点图,我想更新图形的数据(移动滑块时)而不更改 3D 视图。
即使使用此解决方案,3D 视图也会重置:
@app.callback(Output('graph', 'figure'),
Input('slider', 'value'),
State('graph', 'figure'))
def update_fig(value, figure):
if value is not None:
data = new_data(value)
figure['data'][0]['x'] = data['x']
figure['data'][0]['y'] = data['y']
figure['data'][0]['z'] = data['z']
return figure
else:
return figure
Run Code Online (Sandbox Code Playgroud)
是否可以只更新点的坐标?
我希望我的等高线图网格引用相同的颜色条,但我得到了四个堆叠的颜色条。我怎样才能只有一个颜色条,其数值引用所有图中的数据?或者,换句话说,我的绘图颜色如何引用相同的颜色条?
这是测试代码:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
z1 = [[2, 4, 7, 12, 13, 14, 15, 16],
[3, 1, 6, 11, 12, 13, 16, 17],
[4, 2, 7, 7, 11, 14, 17, 18],
[5, 3, 8, 8, 13, 15, 18, 19],
[7, 4, 10, 9, 16, 18, 20, 19],
[9, 10, 5, 27, 23, 21, 21, 21],
[11, 14, 17, 26, 25, 24, 23, 22]]
z2 = [[20, 44, 7, 120, 1, 1, 5, 16],
[3, 10, …Run Code Online (Sandbox Code Playgroud) python ×7
pandas ×3
plotly ×3
colorbar ×1
contour ×1
datatables ×1
dplyr ×1
jquery-ui ×1
jupyter ×1
jupyter-lab ×1
matplotlib ×1
merge ×1
numpy ×1
plotly-dash ×1
prediction ×1
python-3.x ×1
r ×1
regression ×1
scikit-learn ×1