mode(x).mode [0]的含义是什么?(What is the meaning of mode(x).mode[0]?)
我正在尝试使用包含{small,medium,large}形式的值的python的pandas库来查找数据集的列(名为Outlet_Size)的模式,该格式对应于总共1000行以上的10个不同的插座存储。 在这里输入图像描述 。 对于每个商店类型沿着该列查找模式,使用以下代码:
确定每种插座类型(10种不同类型)
outlet_size_mode = data.pivot_table(values ='Outlet_Size',columns ='Outlet_Type',aggfunc =(lambda x:mode(x).mode [0])) 。
但是我无法理解使用lambda函数模式(x).mode [0]的格式。 那是什么意思?
I am trying to find mode along a column(named Outlet_Size) of a dataset using pandas library of python which contains values in the form of {small, medium,large} corresponding to 10 different outlet stores with total of 1000+ rows.enter image description here. For Finding the mode along that column for each store type the following code was used:
Determing the mode for each type of outlet(10 different types)
outlet_size_mode = data.pivot_table(values='Outlet_Size', columns='Outlet_Type',aggfunc=(lambda x:mode(x).mode[0]) ) .
However I am unable to understand the format of using the lambda function mode(x).mode[0]. What is the meaning of that?
原文:https://stackoverflow.com/questions/47950227
最满意答案
params [:campaign] [:adtag_attributes]是一个不是数组的散列,因此当它在散列上运行“each_with_index”方法时,它将“:code”符号视为索引并引发该错误。
你可以做到这一点
params[:campaign][:adtag_attributes].each do |key,value| #some code end只是在测试中改为跟随
params[:campaign][:adtag_attributes] = []
params[:campaign][:adtag_attributes] << somedata希望这有效
params[:campaign][:adtag_attributes] is a hash not an array, so when it runs "each_with_index" method on the hash it sees ":code" symbol as the index and throws that error.
You can just do this
params[:campaign][:adtag_attributes].each do |key,value| #some code endjust change to following in the test
params[:campaign][:adtag_attributes] = []
params[:campaign][:adtag_attributes] << somedatahopefully this works
相关问答
更多-
PHP等同于Ruby符号(PHP equivalent to Ruby symbol)[2022-03-26]
PHP有可定义的常量,但这在这种情况下并不是非常有用。 所以不行。 使用字符串作为键。 PHP has definable constants, but that's not really very useful in this context. So no. Use strings as keys. -
params [:campaign] [:adtag_attributes]是一个不是数组的散列,因此当它在散列上运行“each_with_index”方法时,它将“:code”符号视为索引并引发该错误。 你可以做到这一点 params[:campaign][:adtag_attributes].each do |key,value| #some code end 只是在测试中改为跟随 params[:campaign][:adtag_attributes] = [] params[:camp ...
-
@tobethrown.each.with_index do |a, i| j = a.index(chkdump) return [i, j] if j end @tobethrown.each.with_index do |a, i| j = a.index(chkdump) return [i, j] if j end
-
负数组索引从结尾向后计数。 -1是最后一个元素。 见: http : //www.ruby-doc.org/core-1.9.3/Array.html#method-i-5B-5D Negative array indices count backwards from the end. -1 is the last element. See: http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-5B-5D
-
再次将它包裹在[] 你需要一对数组 ,因为一个Hash可以包含许多对,并且该特性反映在它的构造函数接受的内容中。 单对是具有2个元素的数组 。 Hash[ [:a, [1,2,3]] ] 这是一个Hash.[]的调用,只有一对 [:a, [1,2,3]] 。 为了使它成为一对数组,再次换行,获得[[:a, [1,2,3]]]或 Hash[[[:a, [1,2,3]]] # ↑↑↑ # ||\_pair # |\_array of pairs # \_call to Hash.[] 这里方 ...
-
如何使用Ruby的Symbol#to_proc访问数组中的数组?(How to access arrays within arrays using Ruby's Symbol#to_proc?)[2021-11-16]
你不能。 您只能传递没有参数的方法。 在您的情况下,您需要提供0作为参数,您只能使用块语法。 另一方面,您可以使用first一种方法实现相同的目的: [[a,1],[b,2],[c,3]].map(&:first) 编辑: Joerg和tokland的答案都激励我进行一些实验。 你实际上可以这样做: arr = [[:a, 1], [:b, 2], [:c, 3]] arr.each_with_object(0).map(&:[]) #=> [:a, :b, :c] arr.each_with_objec ... -
版本0.14.1之前的pg gem使用方法rb_thread_select 。 在Ruby 2.2中删除了此方法。 根据他们的历史文件 ,2013年3月发布的版本0.15.0不再使用它: == v0.15.0 [2013-03-03] Michael Granger
[...] Enhancements: - Make use of rb_thread_fd_select() on Ruby 1.9 and avoid deprecated rb_threa ... -
Ruby数组索引(Ruby Array Index)[2022-02-14]
尝试each_with_index emails.each_with_index do |email, index| if index == 0 # do something end end try each_with_index emails.each_with_index do |email, index| if index == 0 # do something end end -
PHP表单,带#符号的地址会导致url错误和未识别的索引(PHP Form, Addresses with the # symbol causes url error and unidentified index)[2022-07-08]
在将urlencode($url)传递给链接之前使用它。 Use urlencode($url) before passing it to the link. -
数组的[]符号(The [ ] symbol for arrays)[2021-11-30]
char[]是items的类型。 items仍然只是一个普通变量,您只需使用其名称即可引用它。 (本质上, []在声明数组类型的变量时,或者在索引变量时使用[] ,例如items[0]或items[items.length - 1] 。) char[] is the type of items. items is still just a normal variable, and you can reference it by just using its name. (In essence, the [] ...