我想创建一个交互式 Jupyter 笔记本。我想要一个 Textarea,如果我输入一些文本,就会在我输入的文本上运行一个函数。我想:
text = widgets.Textarea(
value='last',
placeholder='Paste ticket description here!',
description='String:',
disabled=False
)
display(text)
text.on_displayed(show_matches(text.value))
Run Code Online (Sandbox Code Playgroud)
然后我想执行一些魔术show_matches并显示一个 Pandas 数据框 ( diplay(df))。但是,这仅在我显式运行单元格时运行,然后再次仅使用预定义的last字符串运行。我希望它在我写完文本区域时运行,并带有我写的文本。我怎样才能做到这一点(例如:我怎样才能绑定value的Textarea一个Python变量和运行功能,每当价值的变化)?
我正在尝试将按钮连接到函数,因此当我按下按钮时,将使用特定参数调用该函数.我有
class FieldGridWidget : public QWidget
{
Q_OBJECT
public:
FieldGridWidget(QWidget *parent=0);
~FieldGridWidget();
public slots:
void resizeGrid(int n);
private:
QGridLayout* _gridLayout;
QVector<QPushButton*> _buttonGrid;
};
Run Code Online (Sandbox Code Playgroud)
然后按钮
_button3 = new QPushButton("3x3", this);
Run Code Online (Sandbox Code Playgroud)
并且我正在尝试连接它,所以如果单击,则resizeGrid使用参数3调用该函数.为此,我正在尝试
connect(_button3, SIGNAL(clicked()), _fieldGrid, SLOT(resizeGrid(3))); //this is line 21
Run Code Online (Sandbox Code Playgroud)
但是我得到了运行时错误
QObject::connect: No such slot FieldGridWidget::resizeGrid(3) in ../filename.cpp:21
我究竟做错了什么?或者,如果我按下按钮,我怎么能这样做呢resizeGrid(3)?谢谢!
有datediff几个月使用的好方法吗?为了澄清:该datediff方法采用两列并返回两个日期之间已经过的天数.我想在几个月内拥有它.我希望在我的函数中有一个参数,我可以告诉它检查数据,从过去的20,36,无论几个月.如果我只做了约会并将结果除以30(或31),那么结果就不太准确了.我可以使用30.4166667(= 365天/ 12个月),但这对于较短的时期来说都不太准确.那么,有关如何使用datediff它的几个月的提示吗?SQL有它喜欢SELECT DATEDIFF(month, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000');,我在Spark中寻找类似的东西.
我想缩放一个数据帧的列,使其值介于0和1之间.为此,我使用的是一个MinMaxScaler正常工作,但是向我发送混合消息.我正在做:
x = df['Activity'].values #returns a numpy array
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
df['Activity'] = pd.Series(x_scaled)
Run Code Online (Sandbox Code Playgroud)
此代码的消息numero uno是一个警告:
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
好吧,所以具有1d数组的四胞胎将会很快成为现实,所以让我们按照建议重新塑造它:
x = df['Activity'].values.reshape(-1, 1)
Run Code Online (Sandbox Code Playgroud)
现在代码甚至没有运行:Exception: Data must be 1-dimensional抛出.所以我很困惑.1d即将被弃用,但数据也必须是1d ?? 如何安全地做到这一点?这是什么问题?
按照@sascha的要求编辑
x 看起来像这样:
array([ 0.00568953, 0.00634314, …Run Code Online (Sandbox Code Playgroud) 我有两个行数相同的数据框:1434,我想将它们连接到轴 1 中:
res = pd.concat([df_resolved, df1], axis=1)
Run Code Online (Sandbox Code Playgroud)
这两个数据框没有任何同名的列。我只想加入他们,例如:
df1: df2:
col1 col2 | col3 col4
1 0 | 9 0
6 0 | 0 0
=
concatenated_df:
col1 col2 col3 col4
1 0 9 0
6 0 0 0
Run Code Online (Sandbox Code Playgroud)
这在这样的一个小例子上工作得很好,但由于某种原因,如果我在我的原始数据集上尝试它,我最终会得到很多 NaN 行,这对我来说太大而无法监督(我试图加入 1434x24 和 1434x17458 形状的数据帧)。所以结果有点像:
concatenated_df:
col1 col2 col3 col4
col1 col2 col3 col4
1 0 9 0
6 0 0 0
NaN NaN 0 0
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么。你有什么想法是如何发生的吗?我尝试通过将 _xyz 字符串附加到列名来重命名较小数据框中的所有列,但问题保持不变。
我有一个具有多个级别的if-elif-else结构,但是最后一级else始终是同一条语句:
if statement1:
if something:
do_thing()
elif something_else:
if something_something:
do_thing_something()
elif somethingg:
do_thingg()
else:
do_default()
else:
do_default()
else:
do_default()
Run Code Online (Sandbox Code Playgroud)
如您所见,我使用了do_default()3次,并且感觉有更好的方法。这基本上是一个default在switch-case其他语言中的语句,但是Python没有switch-case。我想知道是否还有其他方法可以更优雅地/“ Pythonly”解决此问题?还是使用字典或实现我自己的唯一方法switch-case?
我正在尝试安装一些 Python 包,即tokenizers来自 Huggingface 的包transformers,它显然需要 Rust。所以我在我的 Docker 版本上安装 Rust:
FROM nikolaik/python-nodejs\nUSER pn\nWORKDIR /home/pn/app\n\nCOPY . /home/pn/app/\nRUN ls -la /home/pn/app/*\nRUN curl https://sh.rustup.rs -sSf | sh -s -- -y\n\nENV PATH ~/.cargo/bin:$PATH\n\n# Install Python dependencies.\nRUN pip install --upgrade pip\nRUN pip install -r requirements.txt\nRUN python load_model.py\n\n# to be equal to the cores available.\nCMD exec gunicorn --bind :$PORT --workers 4 --threads 4 app:app\nRun Code Online (Sandbox Code Playgroud)\n但是,安装分词器时似乎pip找不到:Rust
Building wheels for collected packages: tokenizers\n#11 103.2 Building wheel for tokenizers (pyproject.toml): …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 StreamReader 读取文件,但在使用时出现错误 path
参数 1:无法从“字符串”转换为 System.IO.Stream
尽管从文档中很清楚,您应该能够使用字符串。
我在这里缺少什么?
public MyClass Load(String path)
{
try
{
// exception in this line, `path` is underlined with red
using (StreamReader reader = new StreamReader(path))
{
String line = reader.ReadLine();
// ... etc
Run Code Online (Sandbox Code Playgroud) LabelEncoder不会“记住”参数。当我使用它拟合并转换数据然后询问参数时,我得到的只是{}。这使得不可能在新数据上重复使用编码器。
例:
from sklearn.preprocessing import LabelEncoder
encode = LabelEncoder()
encode.fit_transform(['one', 'two', 'three'])
print(encode.get_params())
Run Code Online (Sandbox Code Playgroud)
不确定预期的格式,但是我期望类似 {['one', 0], ['two', 1], ['three', 2]}
实际结果: {}
我上线了:
Darwin-16.7.0-x86_64-i386-64bit
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
NumPy 1.12.1
SciPy 0.19.0
Scikit-Learn 0.18.1
Run Code Online (Sandbox Code Playgroud) 我无论如何都无法在GPS中编译(不运行)我的Ada代码.我收到一个错误:
cannot generate code for file random.ads (package spec)
gprbuild: *** compilation phase failed
Run Code Online (Sandbox Code Playgroud)
random.ads文件如下所示:
with Ada.Numerics.Float_Random;
use Ada.Numerics.Float_Random;
package random is
protected randomOut is
procedure Inicializal;
entry Parcel(
randomout: out Positive;
from: in Positive;
to: in Positive := 1
);
private
G: Generator;
Inicializalt: Boolean := False;
end randomOut;
task print is
entry write(what: in String);
end print;
end random;
Run Code Online (Sandbox Code Playgroud)
.gpr文件如下所示:
project Default is
package Compiler is
for Default_Switches ("ada") use ("-g", "-O2");
end Compiler;
for Main use ("hunting.adb"); …Run Code Online (Sandbox Code Playgroud) 我正在尝试遍历数组,计算一些值并将它们存储在另一个数组(output)中.但是,我尝试的(见下文)始终打印最后inarray一个计算的最后一个值sum(不是最大值,按预期),并且output数组也只包含最后一个值.我认为output.append(sum)应该在sum整个循环中每次都附加值,但事实并非如此.如果我直接打印和值,它会显示在控制台上.我究竟做错了什么?
def discountCombinations(inarray):
for i in range(len(inarray)):
max = 0
maxi = 0
output = list()
...
#do stuff
...
sum = new_y.sum()
output.append(sum)
print sum
if sum > max:
max = copy.copy(sum)
maxi = copy.copy(i)
print (max,": ", inarray[maxi])
print output
Run Code Online (Sandbox Code Playgroud) 我有一个有 2 个属性的类:
class ButtonPress():
def __init__(self, time, button):
self.time = time
self.button = button
Run Code Online (Sandbox Code Playgroud)
我创建一个列表,ButtonPress其中包含对象:
buttonlist = []
buttonlist.append(ButtonPress("25", "a")
buttonlist.append(ButtonPress("5", "b"))
Run Code Online (Sandbox Code Playgroud)
如何检查列表中的任何对象是否具有特定time值?我想:
if "25" in buttonlist[:]['time']
print("yaaay")
else:
print("feck")
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。
python ×6
scikit-learn ×2
ada ×1
any ×1
apache-spark ×1
arrays ×1
attributes ×1
c# ×1
c++ ×1
class ×1
docker ×1
docker-build ×1
gnat ×1
java ×1
pandas ×1
pip ×1
python-3.x ×1
qt ×1
rust ×1
uwp ×1
widget ×1