如下所示:
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)
以上这篇pandas使用apply多列生成一列数据的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。