回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有两个数据帧,需要用第二个数据帧中的相应值更新第一个中的某些列,然后更改日期列以反映发生了更改。在</p>
<pre><code>today = datetime.datetime.today().date()
df1 = pd.DataFrame([['alpha','foo','buzz','fox',datetime.date(2017,5,31),np.nan],['Beta','foo','flop','cat',datetime.date(2017,8,11),datetime.date(2017,9,19)],
['Gamma','bar','honk','sheep',datetime.date(2017,8,12),np.nan],['omega','bar','growl','dog',datetime.date(2017,2,23),datetime.date(2017,3,2)]],
columns = ['type','col1','col2','enteredCol','CreationDate','lastUpdateDate']).set_index(['type'])
print df1
col1 col2 enteredCol CreationDate lastUpdateDate
type
alpha foo buzz fox 2017-05-31 NaN
Beta foo flop cat 2017-08-11 2017-09-19
Gamma bar honk sheep 2017-08-12 NaN
omega bar growl dog 2017-02-23 2017-03-02
df2 = pd.DataFrame([['alpha','bar','buzz'],['Beta','foo','twist'],['Gamma','bar','honk']], columns = ['type','col1','col2']).set_index(['type'])
print df2
col1 col2
type
alpha bar buzz
Beta foo twist
Gamma bar honk
</code></pre>
<p>如果df2中的col1或col2不同,我需要更新df1中的相应值。如果进行了更改,则需要将lastUpdateDate设置为今天的日期</p>
^{pr2}$
<p>想我怎么做?我可以手动合并每个已更改的列并进行比较,但有许多列需要检查。数据框更新()没有提供一种方法来说明值已更改,或者我也可以使用它。在</p>