简体   繁体   English

基于另一个(熊猫)中的值递增列中的值

[英]Incrementing Values in Column Based on Values in Another (Pandas)

I'd like to find a simple way to increment values in in one column that correspond to a particular date in Pandas. 我想找到一种简单的方法来增加一栏中对应于熊猫中特定日期的值。 This is what I have so far: 这是我到目前为止的内容:

old_casual_value = tstDF['casual'].loc[tstDF['ds'] == '2012-10-08'].values[0]
old_registered_value = tstDF['registered'].loc[tstDF['ds'] == '2012-10-08'].values[0]

# Adjusting the numbers of customers for that day.
tstDF.set_value(406, 'casual', old_casual_value*1.05)
tstDF.set_value(406, 'registered', old_registered_value*1.05)

If I could find a better and simpler way to do this (a one-liner), I'd greatly appreciate it. 如果我能找到一种更好,更简单的方法(单线),我将不胜感激。

Thanks for your help. 谢谢你的帮助。

The following one liner should work based on your limited description of your problem. 根据您对问题的有限描述,以下一种衬板应该可以工作。 If not, please provide more information. 如果没有,请提供更多信息。

#The code below first filters out the records based on specified date and then increase casual and regisitered column values by 1.05 times.
tstDF.loc[tstDF['ds'] == '2012-10-08',['casual','registered']]*=1.05

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM