0

I trying to update column in data frame one same as herehttp://stackoverflow.com/questions/24768657/replace-column-values-based-on-another-dataframe-python-pandas-better-way. However i am not able to do so -

df = pd.read_csv('Analyzed_test.csv')
df['rule_prediction'] = " " # created a column
a1 = pd.read_csv('D:\Junk\ML\\files\\Analyzed_rule1.csv')
a2 = pd.read_csv('D:\Junk\ML\\files\\Analyzed_rule2.csv')
a3 = pd.read_csv('D:\Junk\ML\\files\\Analyzed_rule3.csv')
a4 = pd.read_csv('D:\Junk\ML\\files\\Analyzed_rule4.csv')

df.loc[df.ID.isin(a1.ID), ['rule_prediction']] = a1[['rule_prediction']]
df.loc[df.ID.isin(a2.ID), ['rule_prediction']] = a2[['rule_prediction']]
df.loc[df.ID.isin(a3.ID), ['rule_prediction']] = a3[['rule_prediction']]
df.loc[df.ID.isin(a4.ID), ['rule_prediction']] = a4[['rule_prediction']]

#print t.count
#print self.df.head()
df.to_csv('D:\Junk\ML\\files\\output.csv')

When i open output.csv i see no values populated.

Columns in Analyzed_rule[1-4].csv dataframe in Analyzed_rule1.csv

The one i want to update is - Analyzed_test.csv to output.csv based on ID columns matched.

Thanks in advance.

SKU_MIG
  • 11
  • 1
  • 8

0 Answers0