根据列值

时间:2015-12-20 02:56:58

标签: python pandas

我想重新采样此DataFrame:

import pandas as pd
from StringIO import StringIO

mycsv = StringIO("""
time;A;B
2015-12-06T22:00:00.000000Z;1.08703;1.1
2015-12-07T22:00:05.000000Z;1.08682;2.1
2015-12-07T22:00:05.000000Z;1.08682;3.5
2015-12-08T22:01:20.000000Z;1.08683;5.8
2015-12-09T22:01:30.000000Z;1.08676;6.1
2015-12-10T00:03:00.000000Z;1.08675;7.3
2015-12-06T22:03:50.000000Z;1.08676;12.0
""")
df = pd.read_csv(mycsv, delimiter=';', parse_dates=True, index_col='time', header=0)

每次最后一列值只是< = 4 * k,其中k是一个整数,即我想要这个结果:

time;A;B
2015-12-07T22:00:05.000000Z;1.08682;3.5       # 3.5 is the last value <= 4.0
2015-12-10T00:03:00.000000Z;1.08675;7.3       # 7.3 is the last vakue <= 8.0
2015-12-06T22:03:50.000000Z;1.08676;12.0      # 1é.0 is the last value <= 12.0

如何使用pandas执行此操作,即根据列上的条件重新取样?

0 个答案:

没有答案