Calculate, manipulate data and add a column. Sort a column.
def value_to_float(x):
if type(x) == float or type(x) == int:
return x
if 'K' in x:
if len(x) > 1:
return float(x.replace('K', '')) * 1000
return 1000.0
if 'M' in x:
if len(x) > 1:
return float(x.replace('M', '')) * 1000000
return 1000000.0
if 'B' in x:
return float(x.replace('B', '')) * 1000000000
return 0.0
df1 = pd.DataFrame(data_frame, columns=['Name', 'Wage', 'Value'])
value = df1['Value'].replace('[\€,]', '', regex=True).apply(value_to_float)
wage = df1['Wage'].replace('[\€,]', '', regex=True).apply(value_to_float)
df1['Wage'] = wage
df1['Value'] = value
df1['difference'] = df1['Value'] - df1['Wage']
df1.sort_values('difference', ascending=False) # Used in Jupyter Notebook: