import pandas as pd
import StringIO

table_buffer = StringIO.StringIO('''a b
2007-01-08  0.786667        270
2007-01-09  0.853333        280
2007-01-10  0.866667        282
2007-01-11  0.880000        277
2007-01-12  0.880000        266
2007-01-15  0.866667        279''')
df = pd.read_table(table_buffer, sep='\s+')

def calc_c(row):
    if row.a > 0.5 and row.a < 0.9:
        return row.b
    else:
        return None

df['c'] = df.apply(calc_c, axis=1)

# 对于简单的条件可以用匿名函数
df['c'] = df.apply(lambda row: row.b if row.a > 0.5 and row.a < 0.9 else None, axis=1)

 

refer to:

https://www.zhihu.com/question/54631460

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-05-07
  • 2021-10-28
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-01-04
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案