我有2个计数器(来自集合的计数器),我想将一个附加到另一个,而第一个计数器的重叠键将被忽略.像dic.update(python词典更新)
例如:
from collections import Counter
a = Counter(a=4, b=0, c=1)
b = Counter(z=1, b=2, c=3)
Run Code Online (Sandbox Code Playgroud)
所以类似(忽略第一个计数器的重叠键):
# a.update(b)
Counter({'a':4, 'z':1, 'b':2, 'c':3})
Run Code Online (Sandbox Code Playgroud)
我想我总是可以将它转换成某种字典,然后将其转换回Counter,或使用条件.但我想知道是否有更好的选择,因为我在一个非常大的数据集上使用它.
我有一个带有(标记的)集群的数据集。我试图找到每个集群的质心(一个向量,他的距离是集群的所有数据点的最小距离)。
我找到了许多执行聚类的解决方案,然后才找到质心,但我还没有找到现有的质心。
Python schikit-learn 是首选。谢谢。
有没有办法在 Kusto KQL 中连接列?
例如,对于MySQL (v8) 中world
具有列的某些数据集:name
select group_agg(name) from world;
Run Code Online (Sandbox Code Playgroud)
会导致:
| string_agg |
|-----------------------------------------------|
| Afghanistan,Azerbaijan,Bahrain,Bangladesh,... |
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行一个简单的 Dockerfile,它运行 python 脚本并采用一些环境变量作为参数(使用 argparser):
FROM python:2.7
COPY . /app
WORKDIR /app
RUN pip install argparse
ENV POOL "pool_argument"
CMD ["python", "script.py", "--pool", "${POOL}"]
Run Code Online (Sandbox Code Playgroud)
和我的Python脚本script.py
:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--pool', required=True)
known_args, unknown_args = parser.parse_known_args()
print("Args: {}".format(known_args))
Run Code Online (Sandbox Code Playgroud)
构建并运行后,我得到:
Args: Namespace(pool='${POOL}')
Run Code Online (Sandbox Code Playgroud)
我尝试了很多变体,但似乎都不起作用。
我在 Kusto 中有一张表11111111_1111_1111_1111_111111111111
,我想知道该表的创建时间。
我认为此信息将出现在show table details命令中:
.show table 11111111_1111_1111_1111_111111111111 details
Run Code Online (Sandbox Code Playgroud)
但我在那里看不到它。
在哪里可以找到该表的创建时间?
我怎样才能实现下面的SQL查询在KQL中使用偏移量进行分页查询。
select * from testtable where code = '88580' limit 1000 offset 111
Run Code Online (Sandbox Code Playgroud)
我在 KQL 中找不到任何函数可以像 SQL 中的偏移量一样
我正在尝试执行以下查询:
SELECT COUNT(*) FROM ns123.foo WHERE ttl < 60 * 60 * 24
Run Code Online (Sandbox Code Playgroud)
我从Aerospike AQL count(*) SQL 模拟脚本中找到了 lua 脚本来执行COUNT(*)
使用带有上述 LUA 脚本的 Python,我尝试将 UDF 与读取策略一起应用:
client.udf_put('aggr_functions.lua')
query = client.query('ns123', 'foo')
policy = {
'expressions':
exp.LT(exp.TTL(), 60 * 60 * 24).compile()
}
query.apply('aggr_functions', 'count_star', [])
records = query.results(policy)
print(records)
Run Code Online (Sandbox Code Playgroud)
我被抛出:
Traceback (most recent call last):
...
records = query.results(policy)
exception.UnsupportedFeature: (16, 'AEROSPIKE_ERR_UNSUPPORTED_FEATURE', 'src/main/aerospike/aerospike_query.c', 348, False)
Run Code Online (Sandbox Code Playgroud)
对 Python3.8 库和服务器使用 Aerospike 6.1.x。
我试图规范化df并保存列和行的索引/标题。
Sym1 Sym2 Sym3 Sym4
1 1 1 1 2
8 1 3 3 2
9 1 2 2 2
24 4 2 4 1
scaler = MinMaxScaler(feature_range=(0, 1), copy=True)
scaler.fit(df)
normData = pd.DataFrame(scaler.transform(df))
Run Code Online (Sandbox Code Playgroud)
但是我得到了countinus行和同伴:
0 1 2 3
0 0 0 0 0.8
1 0 1 0.65 0.8
2 0 0.24 0.5 0.2
3 0.5 0.5 0.5 0.25
Run Code Online (Sandbox Code Playgroud)
我想要一个这样的数据框:
Sym1 Sym2 Sym3 Sym4
1 0 0 0 0.8
8 0 1 0.65 0.8
9 0 0.24 0.5 0.2
24 …
Run Code Online (Sandbox Code Playgroud) 我有一个使用 gorilla/mux v1.7.3 和 gorilla/context v1.1.1 在 Go1.13 中编写的 REST API。
我想记录每个请求的持续时间和状态代码。我已经有了一个基本的工作版本,但我想知道是否有一个更干净的选项。
我有大约 20 个 HTTP 调用。我们以其中一个为例:
client.HandleFunc("/register", register.Handle).Methods("POST")
Run Code Online (Sandbox Code Playgroud)
的签名register.Handle
是:
func Handle(w http.ResponseWriter, r *http.Request) { ... }
Run Code Online (Sandbox Code Playgroud)
因此,为了记录每个请求持续时间和状态代码,我简单地register.Handle
用“日志处理程序”包装方法处理程序:
client.HandleFunc("/register", log.HandleRequestWithLog(register.Handle)).Methods("POST")
Run Code Online (Sandbox Code Playgroud)
当log.HandleRequestWithLog
只是对函数执行进行计时,并使用返回的状态代码进行记录(使用 Azure 指标进行记录):
func HandleRequestWithLog(h func(http.ResponseWriter, *http.Request) int) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
startTime := time.Now()
statusCode := h(writer, request)
duration := time.Now().Sub(startTime)
trace := appinsights.NewRequestTelemetry(request.Method, request.URL.Path, duration, string(rune(statusCode)))
trace.Timestamp = time.Now()
client.Track(trace)
}
}
Run Code Online (Sandbox Code Playgroud)
因此,为了提取状态代码,我需要每个 HTTP 方法都返回状态代码。所以我将签名更改为:
func Handle(w …
Run Code Online (Sandbox Code Playgroud) 考虑以下数据框:
import pandas as pd
df = pd.DataFrame(["What is the answer",
"the answer isn't here, but the answer is 42" ,
"dogs are nice",
"How are you"], columns=['words'])
df
words
0 What is the answer
1 the answer isn't here, but the answer is 42
2 dogs are nice
3 How are you
Run Code Online (Sandbox Code Playgroud)
我想计算某个字符串出现的次数,可能在每个索引中重复几次。
比如我想统计the answer
出现的次数。我试过:
df.words.str.contains(r'the answer').count()
Run Code Online (Sandbox Code Playgroud)
我希望有一个解决方案,但输出是4
. 我不明白为什么。the answer
出现3次。
What is **the answer**
**the answer** isn't here, but **the answer** is 42 …
Run Code Online (Sandbox Code Playgroud) 我有以下数据框(df):
Items Category Quantity Weight(each)
Spoon Kitchen 2 0.7
Tent Shelter 1 80.0
Sleeping Bag Shelter 1 20.0
Sunscreen Health 2 5.0
Water Bottles Kitchen 2 35.0
Run Code Online (Sandbox Code Playgroud)
我想统计每个类别的数量,以及按类别划分的权重的平均值。
所需的输出:
count(Quantity) mean(Weight)
Category
Kitchen 4 17.5
Shelter 2 50.0
Health 2 5.0
Run Code Online (Sandbox Code Playgroud)
我知道如何单独进行。但我不确定如何将它们合并在一起。分别地:
df.groupby('Category')['Quantity'].agg(['count'])
df.groupby('Category')['Weight(each)'].agg(['mean'])
Run Code Online (Sandbox Code Playgroud) python ×7
azure ×3
dataframe ×3
kql ×3
pandas ×3
scikit-learn ×2
adx ×1
aerospike ×1
centroid ×1
contains ×1
counter ×1
dictionary ×1
docker ×1
dockerfile ×1
go ×1
gorilla ×1
group-by ×1
logging ×1
mysql ×1
python-2.7 ×1
python-3.x ×1
regex ×1
rest ×1
sql ×1