在Excel列A中,值为[1,2,4,4,5,5]。答案是使用新列B:B2 = A2-A1 = 1,B3 = A3-A2 = 2,B4 = A4-A3 = 0我不介意新列的第一行得到0 >
df = pd.DataFrame({'a':[6,2,4,5], 'b':[3,4,8,7]})
#Columnn c based off b
df['c] = [0,1,4,-1]
# The first value is a zero by default in the new column
不起作用
df['c'] = df.apply(lambda x: x.d[n+1] - x.d[n], axis=1)
#Columnn c based off b from above
df['c] = [0,1,4,-1]
# The first value is a zero by default in the new column