python - Merging dataframes together in a for loop -
i have dictionary of pandas dataframes, each frame contains timestamps , market caps corresponding timestamps, keys of are:
coins = ['dashcoin','litecoin','dogecoin','nxt']
i create new key in dictionary 'merge' , using pd.merge method merge 4 existing dataframes according timestamp (i want completed rows using 'inner' join method appropriate.
sample of 1 of data frames:
data2['nxt'].head() out[214]: timestamp nxt_cap 0 2013-12-04 15091900 1 2013-12-05 14936300 2 2013-12-06 11237100 3 2013-12-07 7031430 4 2013-12-08 6292640
i'm getting result using code:
data2['merged'] = data2['dogecoin'] coin in coins: data2['merged'] = pd.merge(left=data2['merged'],right=data2[coin], left_on='timestamp', right_on='timestamp')
but repeats 'dogecoin' in 'merged', if data2['merged']
not = data2['dogecoin']
(or similar data) merge function won't work values non existent in 'merge'
edit: desired result create 1 merged dataframe seen in new element in dictionary 'data2' (data2['merged']), containing merged data frames other elements in data2
try replacing generalized pd.merge()
actual named df must begin dataframe @ least first one:
data2['merged'] = data2['dashcoin'] # leave out first element coin in coins[1:]: data2['merged'] = data2['merged'].merge(data2[coin], on='timestamp')
Comments
Post a Comment