Pandas适用,如何合并返回的结果

时间:2017-04-11 03:26:06

标签: python pandas dataframe append apply

在python pandas apply中,应用函数占用Dataframe的每一行并返回另一个Dataframe,如何通过应用返回(追加)这些Dataframe的组合?例如:

# this is an example

import pandas as pd
import numpy as np
def newdata(X, data2):
    return X - data2[data2['no']!=X['no']].sample(1,random_state=100)

col = ['no','a','b']
data1 = pd.DataFrame(np.column_stack((range(5),np.random.rand(5,2))),columns=col)
data2 = pd.DataFrame(np.column_stack((range(3),np.random.rand(3,2))),columns=col)
Newdata = data1.apply(newdata, args=(data2,), axis=1)

0 个答案:

没有答案