pandas使用apply多列生成一列数据的实例
如下所示:
import pandas as pd def my_min(a, b): return min(abs(a),abs(b))
s = pd.Series([10.0247,10.0470, 10.0647,10.0761,15.0800,10.0761,10.0647,10.0470,10.0247,10.0,9.9753,9.9530,9.9353,9.9239,18.92,9.9239,9.9353,9.9530,9.9753,10.0]) df = pd.DataFrame(s) df.columns=['value'] df['val_1'] = df['value'].diff() df['val_2'] = df['val_1'].shift(-1) df['val'] = df.apply(lambda row: my_min(row['val_1'], row['val_2']), axis=1)
相关推荐
三石 2020-10-30
roamer 2020-10-29
三石 2020-10-29
wangquannuaa 2020-10-15
wangquannuaa 2020-09-29
jzlixiao 2020-09-15
wangquannuaa 2020-08-30
三石 2020-08-23
逍遥友 2020-08-21
jzlixiao 2020-08-18
wangquannuaa 2020-08-17
QianYanDai 2020-08-16
cjsyrwt 2020-08-14
jzlixiao 2020-07-29
xirongxudlut 2020-07-20
mmmjyjy 2020-07-16
QianYanDai 2020-07-05
QianYanDai 2020-07-05
june0 2020-07-04