小编use*_*963的帖子

Postgres:在int数组中查找最大值?

使用Postgres 9.3 ...

有人可以解释为什么我不能直接在unnested阵列上使用max函数..?

据我所知,不需要的函数返回一个"setof"就像select语句一样.那么为什么这个查询的简短版本不起作用?(我是否在概念上遗漏了某些内容,或者我的问题与语法有关?)

table: foo_history: 

id | history::smallint
----------------------------------- 
1  |  {10,20,30,50,40}
Run Code Online (Sandbox Code Playgroud)

这不起作用?

Select id, max(unnest(history)) as vMax from foo_history;
Run Code Online (Sandbox Code Playgroud)

......但这个确实......?

WITH foo as (
    select id, unnest(history) as history 
    from foo_history
)
Select 
    id, max(history) as vMax
From foo 
Group by id;
Run Code Online (Sandbox Code Playgroud)

arrays postgresql max postgresql-9.3

3
推荐指数
3
解决办法
7193
查看次数

pandas value_counts(显示值和比率)

作为 pandas 的新手,我希望从特定列中获取值的计数以及单个帧中的百分比计数。我可以得到其中之一,但不知道如何将它们添加或合并到一个框架中。想法?

框架/表格应该是这样的:

some_value, count, count(as %)
Run Code Online (Sandbox Code Playgroud)

这是我所拥有的...

import numpy as np
import pandas as pd 

np.random.seed(1)
values = np.random.randint(30, 35, 20)

df1 = pd.DataFrame(values, columns=['some_value'])
df1.sort_values(by=['some_value'], inplace = True)
df2 = df1.value_counts()
df3 = df1.value_counts(normalize=True)

print(df2)
print("------")
print(df3) 
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

3
推荐指数
1
解决办法
3912
查看次数

标签 统计

arrays ×1

dataframe ×1

max ×1

pandas ×1

postgresql ×1

postgresql-9.3 ×1

python ×1