Hi,
I'm trying to update python dataframes, but it is not working as expected.
Frame1
description|cusip|value1|value2|value3|VALUE4
this_is_file3|ATG0104|30|14|45|500
this_is_file1|ATG0102|10|12|13|200
this_is_file11|ATG0101|20|30|40|105
this_is_file2|ATG0103|20|22|23|300
Frame2
description|CUSIP|VALUE3|value2|value4|value1
this_is_file2_updated|ATG0102|34.40|10.21|100.14|90.12
this_is_file1_updated|ATG0101|12.50|11.34|13.76|104.2
this_is_file3_updated|ATG0103|10.13|9.12|14.34|405.14
Result after updating(value1, value2, value3) of Frame1 with Frame2 based on Key(cusip/CUSIP)
description|CUSIP|value1|value2|VALUE3|VALUE4
this_is_file1_updated|ATG0101|104.2|11.34|12.5|200
this_is_file2_updated|ATG0102|90.12|10.21|34.4|105
this_is_file3_updated|ATG0103|405.14|9.12|10.13|300
this_is_file3|ATG0104|30.0|14.0|45.0|500
I'm indexing the frames by Key(cusip/CUSIP) and then performing the update on columns (value1, value2 and VALUE3).
As you can observe, the value of last column(VALUE4) is not aligned properly with the keys. What might be the issue?
The following is the code that I'm using:
def replace(self, dataobj, k_options, K_options, d_options, D_options,S_options):
print('Before renaming column names');
print(list(self.frame.columns.values));
for j in range(0, len(k_options)):
self.frame.rename(columns = {k_options[j]: K_options[j]}, inplace=True);
for i in range(0, len(d_options)):
self.frame.rename(columns = {d_options[i]: D_options[i]}, inplace=True);
print('After renaming column names');
print(list(self.frame.columns.values));
self.frame.set_index(K_options);
dataobj.frame.set_index(K_options);
print('Other Frame: ', dataobj.frame);
self.frame.update(dataobj.frame, join='left', overwrite=True);
print('Updated Frame: ', self.frame);
time.sleep(2000);
self.frame.to_csv(S_options[0]+'_new.csv', sep='|',index=None, na_values=[""]);
print('Updated');
Inputs:
k_options ['cusip']
K_options ['CUSIP']
d_options "value1|value2|value3"
D_options "value1|value2|VALUE3"
Thanks,
Vanan.