import pandas as pd
import numpy as np
# suppose this is your df
df
Out[83]:
fruit_type temp count
0 apple 12 4
1 apple 14 6
2 pear 12 6
3 pear 16 2
4 grape 12 5
5 peach 9 33
6 peach 6 3
# prob part
df['prob'] = df.groupby('fruit_type')['count'].transform(lambda count: ((count) / count.sum()))
# total part
df['total_count'] = df.groupby('fruit_type')['count'].transform(lambda count: count.sum())
df
Out[87]:
fruit_type temp count prob total_count
0 apple 12 4 0.4000 10
1 apple 14 6 0.6000 10
2 pear 12 6 0.7500 8
3 pear 16 2 0.2500 8
4 grape 12 5 1.0000 5
5 peach 9 33 0.9167 36
6 peach 6 3 0.0833 36
从ServiceStack.OrmLite
加载Views
吗?
https://github.com/ServiceStack/ServiceStack.OrmLite
最新版本。
我的数据库中有一些Sql Server
我希望使用Views
加载ServiceStack.OrmLite
Tables
中的ServiceStack
?
答案 0 :(得分:2)
ServiceStack.OrmLite
将对象表示的查询转换为SQL查询。
因此,如果您可以从SQL字符串调用您的视图(在这种情况下),那么您可以使用ServiceStack.OrmLite