English 中文(简体)
消除价值估算中的重复计算
原标题:Removing redundancy in value counts

我有这样的数据框架:

api_spec_id info_version     label
117455          1.PreR15.0.0    
117455          1.0.0   
117455          1.0.1           patch
117455          1.0.1   
117455          1.0.2           patch
117455          1.1.0.alpha-1   minor.patch.pre
117455          1.1.0.alpha-2   pre
117455          1.1.0.alpha-3   pre
117455          1.1.0           pre
117455          1.1.1           patch
117455         1.2.0-alpha.1    minor.patch.pre
117455         1.2.0-alpha.2    pre
117455         1.2.0-alpha.3    pre
117455         1.2.0-alpha.4    pre
117455         1.2.0            pre
117455         1.2.1            patch

import pandas as pd

data = {
     api_spec_id : [117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455, 117455],
     info_version : [ 1.PreR15.0.0 ,  1.0.0 ,  1.0.1 ,  1.0.1 ,  1.0.2 ,  1.1.0.alpha-1 ,  1.1.0.alpha-2 ,  1.1.0.alpha-3 ,  1.1.0 ,  1.1.1 ,  1.2.0-alpha.1 ,  1.2.0-alpha.2 ,  1.2.0-alpha.3 ,  1.2.0-alpha.4 ,  1.2.0 ,  1.2.1 ],
     label : [  ,   ,  patch ,   ,  patch ,  minor.patch.pre ,  pre ,  pre ,  pre ,  patch ,  minor.patch.pre ,  pre ,  pre ,  pre ,  pre ,  patch ]
}

df = pd.DataFrame(data)

我想计算<代码>值_counts(),但就我而言是多余的,因此,第一行之后的空贴标签表明该版本没有变化的情况,即想要计算。

但是,正在发生的情况是,这种价值——计值将第一行空行和其他空行合在一起。 我想排除第一个空档,然后在标签仍然空洞的地方算出。

我不清楚我如何能够做到这一点,因此,将非常赞赏任何建议。

问题回答

如果我正确理解你的问题,那么这一例子中的第4行中的空洞标识应算作 TOP/strong>,而不是像头两行一样的另一种空洞的标识? 如果是这样的话,你可以使用<代码>replace系列文件的方法,通过任何(最后——你可以使用一种定期表达方式,但需要列出所有)一套价值,就像你使用<代码><<>flif/code>或 <<<<>>>>code>,以通过缺失的数值来填补:

df["label"].replace(to_replace="", method="ffill").value_counts()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...