...最初私はその後、私は私のパターンにそれらのそれぞれに参加します、両方のデータフレームを同期させるための一般的な指標になります(日付)と私はの列を合計します同じ名前、最終的には両方のデータフレーム(そのうちの一つに追加の列を削除)に参加、
あなたはここ(グーグルから撮影したGoogleの株価との)例を見ることができます:
import numpy as np
import pandas as pd
import datetime as dt
prices = pd.DataFrame([[553.0, 555.5, 549.3, 554.11, 0],
[556.8, 556.8, 544.05, 545.92, 545.92],
[545.5, 546.89, 540.97, 542.04, 542.04]],
index=[dt.datetime(2014,11,04), dt.datetime(2014,11,05), dt.datetime(2014,11,06)],
columns=['Open', 'High', 'Low', 'Close', 'Adj Close'])
corrections = pd.DataFrame([[0, 555.22], [1238900, 0]],
index=[dt.datetime(2014,11,3), dt.datetime(2014,11,4)],
columns=['Volume', 'Adj Close'])
dates = pd.DataFrame(prices.index, columns = ['Dates']).append(pd.DataFrame(corrections.index, columns = ['Dates'])).drop_duplicates('Dates').set_index('Dates').sort(axis=0)
df_corrections = dates.join(corrections).fillna(0)
df_prices = dates.join(prices).fillna(0)
for col in prices.columns:
if col in corrections.columns:
df_prices[col]+=df_corrections[col]
del df_corrections[col]
df_prices = df_prices.join(df_corrections)
fill_value使用するアイテムは、1つのまたは両方のデータフレームに存在しない場合は、あなたが起こるしたいものを明確にすることはできますか?そのアイテムが* one * dataframeに存在しない場合は、ゼロとして扱うべきです---そのデータフレームの値をゼロとして扱い、他のデータフレームの値に追加するかどうか結果のデータフレームの値はゼロでなければなりませんか?また、 'df1 + df2'は、両方が要素を持たない場合はNaNを返すため、動作しません。この場合、あなたは何をしたいですか?結果にゼロが必要ですか? – BrenBarn