当我尝试对齐数据框时,我得到了错误的结果。但我没有得到错误:
dateparse = lambda x: pd.datetime.strptime(x, '%d.%m.%Y')
#well_dates_up_obj=fhist_grouped_hist_data.reset_index(drop=True).set_index(['well_alias','Дата','upper_obj'], drop=False)
well_dates_up_obj=fhist_grouped_hist_data.copy(deep=True)
presdf = reading_csv_files(files_dict, 'davl','cp1251', sep=';' , skipinitialspace=True, header = 0,parse_dates = ['DAT'], date_parser=dateparse)
presdf['well_alias'] = presdf.apply(lambda x: renamefunc(x['NSKV'].upper()), axis = 1);
presdf = presdf.loc[presdf['well_alias'].isin(wells_im_model),:]
presdf.replace({'PPL':0, 'PZAB':0},np.nan, inplace=True)
presdf['area'] = ''
for wellname in set(presdf['well_alias']):
presdf.loc[presdf['well_alias']==wellname,'area'] = wells[wellname].area
presdf=presdf.rename({'GOR':'davlname'},axis='columns')
presdf = presdf.set_index(['area','davlname'], drop=False)
objectsdavl_indxed = objectsdavl.set_index(['area','davlname'], drop=False)
presdf = presdf.reindex(columns = np.append( presdf.columns.values, ['woc', 'liqden', 'obj_alias']))
presdf.loc [:,['woc','liqden','obj_alias']] = objectsdavl_indxed [['woc','den','alias']]。align(presdf,join ='right' ,axis = 0)[0] .to_numpy()
我得到了具有不同索引的错误对齐的数据框。
下面的代码是数据帧的示例:
presdf[['woc', 'liqden', 'obj_alias']].head()
Out[127]:
woc liqden obj_alias
area davlname
AREA1 C1 980.0 0.92 C2
C1 980.0 0.92 C2
C1 980.0 0.92 C2
C1 980.0 0.92 C2
C1 980.0 0.92 C2
objectsdavl_indxed[['woc', 'den', 'alias']].align(presdf, join='right', axis=0)[0].head()
Out[128]:
woc den alias
area davlname
AREA2 C2 980.0 0.92 C2
C2 980.0 0.92 C2
C2 980.0 0.92 C2
C2 980.0 0.92 C2
C2 980.0 0.92 C2
但是我希望得到以下结果:
objectsdavl_indxed[['woc', 'den', 'alias']].align(presdf, join='right', axis=0)[0].head()
Out[128]:
woc liqden obj_alias
area davlname
AREA1 C1 980.0 0.92 C2
C1 980.0 0.92 C2
C1 980.0 0.92 C2
C1 980.0 0.92 C2
C1 980.0 0.92 C2