简体   繁体   中英

Merge 2 dataframe on index with different timestamp in python pandas

I have 2 dataframes with different timestamps and different lengths.

First Dataframe, df , has 1054 rows and looks like this:

第一个数据框

Second Dataframe, df_temp , has 2629 rows and looks like this:

第二个数据框

I have no clue where to begin. The time stamp is almost close and I know how to merge dataframes with similar index but not this one. Any help would be appreciated. Thank you!

df_merged=pd.concat([df,df_temp]).sort_index()

I tried this before as well. When I add these together the index is kind of sorted but it gives me NaN values for where the data is missing.

Can you try this ?

pd.concat([df,df_temp]).sort_index()

or

pd.concat([df,df_temp.rename(columns=dict(zip(df_temp.columns,df.columns)))]).sort_index()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM