简体   繁体   English

Pandas:我想在时间序列中创建一列,其中的值取决于前一行的值

[英]Pandas: I want to create a column in a Time Series where the value depends on the previous row's value

I have a time series dataframe where I need to create a boolean-valued column, which is我有一个时间序列数据框,我需要在其中创建一个布尔值列,即

  • True if the current value is more than 10% different from the previous row's value.如果当前值与前一行的值相差 10% 以上,则为
  • False otherwise否则为

As you have not provided any sample data, so I am not 100% sure, what you exactly want.由于您没有提供任何样本数据,所以我不能 100% 确定您到底想要什么。 But here is what I think you need to do但这是我认为你需要做的

df=pd.DataFrame([np.random.randn(10,1)],columns=['first'])
df['prev']=df.shift(1)
df['prev']-df['first']>df['first']*0.1

暂无
暂无

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

相关问题 Pandas 列取决于其先前的值(行)? - Pandas column that depends on its previous value (row)? Python:如何填充依赖于前一个值(前一行)的Pandas列? - Python: How to populate Pandas column that depends on the previous value (previous row)? 在 Pandas df 中创建新列,其中每一行的值取决于其正上方行中不同列的值 - Creating new column in a Pandas df, where each row's value depends on the value of a different column in the row immediately above it 获取上一行的值并计算新列pandas python - get previous row's value and calculate new column pandas python 根据列的上一个和下一个值,从基于时间的数据创建“增量”日志(pandas df) - Create 'incremental' log (pandas df) from time based data based on column's previous and next value 使用 pandas 我需要创建一个新列,该列采用前一行的值 - Using pandas I need to create a new column that takes a value from a previous row 如何获取 pandas 列中的前一行值 - how can I get a previous row value in pandas column Pandas 与当前行列匹配的先前记录的时间序列累积 - Pandas time series cumsum of previous records matching a column of current row 在pandas中创建一个得分列,其值取决于另一列的百分位数 - Create a score column in pandas whose value depends on the percentile of another column Pandas 列,其中每个值取决于另一个 df 查询 - Pandas column where each value depends on another df query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM