根据timedelta和index修改列值 [英] Amend column values according to timedelta and index

查看:71
本文介绍了根据timedelta和index修改列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在熊猫数据框中更改数据.

I would like to change my data in a pandas dataframe.

我收集的数据需要分配一个步进值.触发阶跃变化的条件有时是时间,高压或温度值.我无法超越第一步:当该行超过一定压力(1100 psi)且在温度(40 C)下时,这就是稀释"阶段.

The data I collect needs to be assigned a step value. The conditions of what triggers a step change are occasionally time or high pressure or temperature values. I cannot get past the first step: When the row is over a certain pressure (1100 psi) and under a temp (40 C), this is the "dilution" phase.

尝试通过以下方式更改值:

When attempting to change the value with:

df.ix[(df['press'] > 1100) & (df['temp'] < 40),'proc'] = 'dilute';

我似乎只修改前两行.

items[0].head()
Out[37]: 
              time       mass       temp       press        proc
time                                                            
00:00:00  10:58:07  21.947102  23.306101    1.830506      dilute
00:00:01  10:58:08  22.076259  23.306101   57.274142      dilute
00:00:02  10:58:09  22.094710  23.306101  196.000203  pressurize
00:00:03  10:58:10  22.113161  23.306101  293.318991  pressurize
00:00:03  10:58:10  22.094710  23.306101  361.161415  pressurize

items[0].tail()
Out[38]: 
              time       mass       temp     press        proc
time                                                          
00:36:12  11:34:19  18.201538  39.798763 -1.678585  pressurize
00:36:13  11:34:20  18.183087  39.719165 -1.444645  pressurize
00:36:14  11:34:21  18.183087  39.671407 -1.444645  pressurize
00:36:15  11:34:22  18.219989  39.703246 -1.444645  pressurize
00:36:16  11:34:23  18.201538  39.758964 -1.444645  pressurize

进一步检查后,索引确实可以正常工作,给了我希望看到稀释发生的索引...

Upon further inspection, the indexing does seem to work, giving me the index where I would expect to see the dilution occur...

print(df.ix[(df['press'] > 1100) & (df['temp'] < 40),'proc'].head(),
                df.ix[(df['press'] > 1100) & (df['temp'] < 40),'proc'].tail())
time
00:00:26    pressurize
00:00:27    pressurize
00:00:28    pressurize
00:00:29    pressurize
00:00:30    pressurize
Name: proc, dtype: object time
00:26:08    pressurize
00:26:09    pressurize
00:26:10    pressurize
00:26:11    pressurize
00:26:12    pressurize
Name: proc, dtype: object

但是,当将其应用于我的数据时,我只更改了前两个值,并且消息-

However, when applying it to my data, I get only the first two values changed, and the message--

FutureWarning:将来,类似布尔型的数组将作为 布尔数组索引值[索引器] =值'

FutureWarning: in the future, boolean array-likes will be handled as a boolean array index values[indexer] = value'

运行烹饪书示例确实可以预期响应.

Running the cookbook examples does give the expected response.

似乎我有一个嵌套索引,但是不清楚为什么,或如何进行修改.这里有几层,对解决方案的搜索并没有被证明是有用的,或者提供了最好的途径来帮助阐明.

It seems that I have a nested index, but I'm not clear on why, or how to go about amending this. There are a few layers here and searches for solutions have not proved useful or provided the best route to help clarify.

我想重设索引并使用数字,但是我需要按值和时间增量对步骤进行排序.

I thought to reset the index, and go with numbers, but I need to sort steps by values and timedeltas.

索引是一个timedelta,我需要对其进行标准化,以便在多个时间段内启动多个运行,以在0秒的同一时间启动所有运行.我的搜索仅产生日期干扰而不是时间,因此我使用timedelta索引将值归一化为零.

The index is a timedelta, which I needed to normalize a number of runs launched over a number of periods to start all runs at the same time 0 seconds. My searches only yield date munging and not time, hence my normalizing values to zero with a timedelta index.

如果有更好的方法来发布此问题,或者更加清晰,请询问.我非常愿意增加清晰度或修饰度.很难预测有用的信息对专业编码员的需求.

If there is a better way to publish this question, or more clarity, please ask. I'm more than willing to add clarity or trim. It is hard to predict what the helpful info would look like to a professional coder.

推荐答案

尝试一下

df['press'].astype('float')
df['temp'].astype('float')

df['proc']  = np.where((df['press'] > 1100) & (df['temp'] < 40),'dilute', "pressurized")

这篇关于根据timedelta和index修改列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆