简体   繁体   中英

Finding the difference between two data-frames

在此处输入图片说明 I'm trying to find the largest income difference between male and female workers. But I'm not sure how to implement the code. I need some assistance.

aa=industries.F_weekly.max()
bb=industries.M_weekly.max()
cc = (nf.loc[nf['M_weekly'] == bb]) - (nf.loc[nf['F_weekly'] == aa])
cc.max()
cc.min()

Let's say your Dataframe is called df. First, calculate the absolute value of salary difference, then print max. This can also be done in one line.

df['salary_delta'] = (df['M_weekly'] - df['F_weekly']).abs()
print(max(df['salary_delta']))

In case you want to find the row where salary difference is the highest then try:

df.loc[df['salary_delta'].idxmax()]

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