For the first bit of code where I subtract initial cost from Total estimated fee this is the error I get:
TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')
When I try df3['initial cost'][df3['initial cost'] < 0] = NaN, the error I get is:
TypeError: '<' not supported between instances of 'str' and 'int'
Sorry about not posting my errors. I'll start posting them from now on.
(Apr-24-2017, 05:35 PM)zivoni Wrote: [ -> ]As both snippsat and nilamo said before, you make it harder by not posting informations about your code and/or errors. Its hard to help when you just say "is not working", neither its helping when you are working with pandas without knowing that you are working with pandas ...
Your code with changes suggested in my previous post works fine for me:
Output:
In [1]: import pandas as pd
...: from numpy import NaN
...: dict3={'initial cost': ['$75000.00','$0.00','$30000.00','$1500.00','$19500.00'],'Total Est. Fee':['$986.00','$1144.00','$522.50', '$
...: 225.00', '$389.50']}
...: df3=pd.DataFrame(dict3)
...: df3['Total Est. Fee']=df3['Total Est. Fee'].str.split('$')
...: df3['Total Est. Fee']=df3['Total Est. Fee'].str.get(1)
...: df3['initial cost']=df3['initial cost'].str.split('$')
...: df3['initial cost']=df3['initial cost'].str.get(1)
...: df3['Total Est. Fee']=pd.to_numeric(df3['Total Est. Fee'],errors='coerce')
...: df3['initial cost'] = pd.to_numeric(df3['initial cost'], errors='coerce')
...: df3['diff']=df3['initial cost']-df3['Total Est. Fee']
...: df3['diff'][df3['diff'] < 0] = NaN
...:
In [2]: df3
Out[2]:
Total Est. Fee initial cost diff
0 986.0 75000.0 74014.0
1 1144.0 0.0 NaN
2 522.5 30000.0 29477.5
3 225.0 1500.0 1275.0
4 389.5 19500.0 19110.5
For the first bit of code where I subtract initial cost from Total estimated fee this is the error I get:
TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')
When I try df3['initial cost'][df3['initial cost'] < 0] = NaN, the error I get is:
TypeError: '<' not supported between instances of 'str' and 'int'
Sorry about not posting my errors. I'll start posting them from now on.
Also, sorry for not posting my response directly to your response. I accidentally made it as a separate entry.