i have one datafrom:
lst = ['Geeks', 'For', 'Geeks', 'is', 'portal', 'for', 'Geeks'] lst2 = ['B', 'C', 'B', 'A', 'Z', 'C', 'B'] df = pd.DataFrame(list(zip(lst, lst2)), columns =['Name', 'val'])
and another df1
lst = ['B', 'A'] lst2 = ['M', 'N'] df1 = pd.DataFrame(list(zip(lst, lst2)), columns =['col1', 'col2'])
if df['val']'s item value is the same with df1['col'] item value then df['val']'s corresponding item value is replaced by corresponding value of df1['col2'], otherwise, the original df['val'] item value does not change. So, how to do with df so that df is converted as :
lst = ['Geeks', 'For', 'Geeks', 'is', 'portal', 'for', 'Geeks'] lst2 = ['M', 'C', 'M', 'N', 'Z', 'C', 'M'] df = pd.DataFrame(list(zip(lst, lst2)), columns =['Name', 'val'])
where 'B' is exchanged to 'M';'A'is exchanged into 'N', the other does not change.
https://stackoverflow.com/questions/66792786/how-to-change-values-of-one-dataframe-by-another-dataframes-column March 25, 2021 at 11:45AM
没有评论:
发表评论