admin管理员组文章数量:1201591
I've got a column ['Duration]
which is an int
datatype. I'm now trying to find out the most occurencing ['Duration']
in a pandas dataframe.
duration = (inter['duration'].mode())
print(duration)
Result:
0 94
Name: duration, dtype: int64
The answer is right, but the datatype is wrong. It should be an integer When I ran type function over the duration variable it shows this
type(duration)
Result:
pandas.core.series.Series
The variable 'duration' should be an integer and not pandas.series. How can I convert it to that?
I've got a column ['Duration]
which is an int
datatype. I'm now trying to find out the most occurencing ['Duration']
in a pandas dataframe.
duration = (inter['duration'].mode())
print(duration)
Result:
0 94
Name: duration, dtype: int64
The answer is right, but the datatype is wrong. It should be an integer When I ran type function over the duration variable it shows this
type(duration)
Result:
pandas.core.series.Series
The variable 'duration' should be an integer and not pandas.series. How can I convert it to that?
Share Improve this question edited Jan 22 at 13:46 jps 22.5k16 gold badges88 silver badges104 bronze badges asked Jan 22 at 13:25 user234568user234568 8154 gold badges14 silver badges25 bronze badges1 Answer
Reset to default 1There can be more than one value that is the mode.
inter = pd.DataFrame({'duration': [1, 2, 3, 1, 1, 2, 2]})
inter['duration'].mode()
# 0 1
# 1 2
# Name: duration, dtype: int64
If you want to pick the first one, just slice:
inter['duration'].mode().iloc[0]
Example:
inter = pd.DataFrame({'duration': [1, 2, 3, 1, 1, 3, 2]})
inter['duration'].mode().iloc[0]
# 1
Otherwise, you will need to decide what to do with the multiple values (e.g. aggregate them as the mean
if this makes sense).
本文标签: pythonHow can I convert this pandasseries result to integerStack Overflow
版权声明:本文标题:python - How can I convert this pandas.series result to integer? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738560584a2099154.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论