我有一个循环收集的数据,并存储在只包含相同数据类型的单独列表中(例如,只包含字符串,只有浮点数),如下所示:
names = ['bar', 'chocolate', 'chips']
weights = [0.05, 0.1, 0.25]
costs = [2.0, 5.0, 3.0]
unit_costs = [40.0, 50.0, 12.0]
Run Code Online (Sandbox Code Playgroud)
我已将这些列表视为表的"列",并希望将它们打印为格式化的表,应该如下所示:
Names | Weights | Costs | Unit_Costs
----------|---------|-------|------------
bar | 0.05 | 2.0 | 40.0
chocolate | 0.1 | 5.0 | 50.0
chips | 0.25 | 3.0 | 12.0
Run Code Online (Sandbox Code Playgroud)
我只知道如何在表行中横向打印列表中的数据,我已经在线查看(以及在此站点上)以获得有关此问题的一些帮助,但是我只是设法找到帮助使它在python 2.7而不是3.5中工作.1这就是我正在使用的.
我的问题是:
如何从上面的4个列表中获取条目以打印到如上所示的表格中.
来自上面列表的每个项目索引是相关联的(即,来自4个列表的条目[0]与相同的项目相关联;条形,0.05,2.0,40.0).
我在熊猫数据框中有这样的数据
id import_id investor_id loan_id meta
35736 unremit_loss_100312 Q05 0051765139 {u'total_paid': u'75', u'total_expense': u'75'}
35737 unremit_loss_100313 Q06 0051765140 {u'total_paid': u'77', u'total_expense': u'78'}
35739 unremit_loss_100314 Q06 0051765141 {u'total_paid': u'80', u'total_expense': u'65'}
Run Code Online (Sandbox Code Playgroud)
如何基于total_expense进行排序,后者是json字段的值,
例如:meta字段上的total_expense
输出应为
id import_id investor_id loan_id meta
35739 unremit_loss_100314 Q06 0051765141 {u'total_paid': u'80', u'total_expense': u'65'}
35736 unremit_loss_100312 Q05 0051765139 {u'total_paid': u'75', u'total_expense': u'75'}
35737 unremit_loss_100313 Q06 0051765140 {u'total_paid': u'77', u'total_expense': u'78'}
Run Code Online (Sandbox Code Playgroud) 所以我有一个这样的 df
In [1]:data= {'Group': ['A','A','A','A','A','A','B','B','B','B'],
'Name': [ ' Sheldon Webb',' Traci Dean',' Chad Webster',' Ora Harmon',' Elijah Mendoza',' June Strickland',' Beth Vasquez',' Betty Sutton',' Joel Gill',' Vernon Stone'],
'Performance':[33,64,142,116,122,68,95,127,132,80]}
In [2]:df = pd.DataFrame(data, columns = ['Group', 'Name','Performance'])
Out[1]:
Group Name Performance
0 A Sheldon Webb 33
1 A Traci Dean 64
2 A Chad Webster 142
3 A Ora Harmon 116
4 A Elijah Mendoza 122
5 A June Strickland 68
6 B Beth Vasquez 95
7 B Betty …Run Code Online (Sandbox Code Playgroud) 我正在查看以下数据(JSON)
{
"FValidation_pipelineMTHXT_v4.5.1_refLibV2": "concordance2/f",
"FValidation_pipelineLPJL": "concordance2/c",
"FCompetenceRuns": "concordance2/b",
"FWGS": "concordance2/a",
"Falidation_pipelineMTHXT": "concordance2/e",
"FValidation_pipelineLPJL_v4.5.1_refLibV2": "concordance2/d"
}
Run Code Online (Sandbox Code Playgroud)
我试图按哈希值排序
for %files.kv -> $key, $value {
Run Code Online (Sandbox Code Playgroud)
提供所需的数据,但我希望对其进行排序。我尝试了20种不同的方法,这些方法不起作用
for %files.sort.kv -> ($key, $value) {
Run Code Online (Sandbox Code Playgroud)
和
for %files.sort: *.value.kv -> ($key, $value) {
Run Code Online (Sandbox Code Playgroud)
它的灵感来自https://docs.perl6.org/routine/sort#(Map)_method_sort ,而且一直都在起作用,但没有一个:(
如何按值对哈希进行排序?
如何将jsonb顺序查询传递到sortable:Active Admin列的选项?
我的模型结构如下:
# User Model
class User < ActiveRecord::Base
has_one :level
end
# Level Model
class Level < ActiveRecord::Base
belongs_to :user
end
# Level Migration
create_table "levels", force: :cascade do |t|
t.integer "user_id"
t.jsonb "ranked_scores"
end
Run Code Online (Sandbox Code Playgroud)
该:ranked_scoreJSON结构是:
# level.ranked_scores
{"stage_1"=>111, "stage_2"=>222, "stage_3"=>333}
Run Code Online (Sandbox Code Playgroud)
我试图排序User使用Level的:ranked_scores属性如下:
# app/admin/user.rb
ActiveAdmin.register User do
controller do
def scoped_collection
end_of_association_chain.includes(:level)
end
end
index do
column "Stage 1 Score", sortable: "level.ranked_scores -> 'stage_1'" do |user|
user.level.ranked_scores['stage_1']
end …Run Code Online (Sandbox Code Playgroud) 我有一个非常大的熊猫数据框,大约有500,000列.每列长约500个元素.对于每列,我需要检索列中top-k元素的(索引,列)位置.
所以,如果k等于2,这就是我的数据框:
A B C D
w 4 8 10 2
x 5 1 1 6
y 9 22 25 7
z 15 5 7 2
Run Code Online (Sandbox Code Playgroud)
我想回来:
[(A,y),(A,z),(B,w),(B,y),(C,w),(C,y),(D,x),(D,y)]
Run Code Online (Sandbox Code Playgroud)
请记住,我有大约500,000列,所以速度是我的主要关注点.有没有合理的方法可以在我的机器上花费整整一周的时间?什么是最快的方式 - 即使它足够快我的数据量?
谢谢您的帮助!
我试图通过多种方式提出这个问题.这是一个难以回答的问题,因为你必须了解正在发生的事情.
我什么时候填写GridView?
该Nieve酒店答案时Page_Load,如果没有一个回发:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = GetStuffToShow();
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于,如果它是回发,则网格不会被填充.网格未填充的原因是因为我们关闭了网格的视图状态.
我们需要始终填充网格,回发与否:
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = GetStuffToShow();
GridView1.DataSource = ds;
GridView1.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
但问题是,如果用户排序列,该OnSorting事件被称为后两者Page_Init和Page_Load:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataSet ds = GetStuffToShow(e.SortExpression, e.SortDirection);
GridView1.DataSource = ds;
GridView1.DataBind();
} …Run Code Online (Sandbox Code Playgroud) 将 sortWithinPartitions 应用于 df 并将输出写入表后,我得到了一个结果,但我不知道如何解释。
df
.select($"type", $"id", $"time")
.sortWithinPartitions($"type", $"id", $"time")
Run Code Online (Sandbox Code Playgroud)
结果文件看起来有点像
1 a 5
2 b 1
1 a 6
2 b 2
1 a 7
2 b 3
1 a 8
2 b 4
Run Code Online (Sandbox Code Playgroud)
它实际上不是随机的,但也不像我期望的那样排序。即,首先按类型,然后是 id,然后是时间。如果我尝试在排序之前使用重新分区,那么我会得到我想要的结果。但由于某种原因,文件的重量增加了 5 倍(100GB 与 20GB)。
我正在向 hive orc 表写入数据,并将压缩设置为 snappy。
有谁知道为什么它是这样排序的,以及为什么重新分区会得到正确的顺序,但尺寸更大?
使用火花2.2。
我有这样的数据框
class col2 col3 col4 col5 col6
A AA 0 5 4 2 15
B AA 4 10 14 12 25
C AA 19 2 8 5 3
D SS 17 5 5 32 12
E AA 14 2 12 14 55
F II 12 17 1 9 0
G SS 10 37 8 2 17
H II 17 7 5 7 14
Run Code Online (Sandbox Code Playgroud)
我想删除所有具有零值的列
class col3 col4 col5
A AA 5 4 2
B AA 10 14 12
C AA …Run Code Online (Sandbox Code Playgroud) columnsorting ×10
sorting ×4
pandas ×3
python ×3
activeadmin ×1
apache-spark ×1
asp.net ×1
comparator ×1
dataframe ×1
datatables ×1
formatting ×1
gridview ×1
hashmap ×1
indexing ×1
jquery ×1
json ×1
list ×1
orc ×1
perl6 ×1
postgresql ×1
r ×1
snappy ×1