huge and weird values after applying some calculations - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: huge and weird values after applying some calculations (/thread-23102.html) |
huge and weird values after applying some calculations - karlito - Dec-11-2019 OK guys, The values I got for some columns are just too huge other are in day/month format (see excel picture) and I was wondering why. Here is my code and the file is here here you can see the excel and the pandas outputs import pandas as pd # Read the file data = pd.read_csv('/your_location/for_test.csv', sep = ';') # Set the index data = data.set_index('Date_Time') # Drop the duplicated rows data = data.drop_duplicates(keep = "first") # Create new columns using Addition and Multiplication data['a1'] = data['x1'] * data['y1'] data['a2'] = data['x2'] * data['y2'] data['a3'] = data['x3'] * data['y3'] data['b1'] = data['x1'] * data['z1'] data['b2'] = data['x2'] * data['z2'] data['b3'] = data['x3'] * data['z3'] data['A'] = (data['a1'] + data['a2'] + data['a3']) * 0.01 data['B'] = (data['b1'] + data['b2'] + data['b3']) * 0.01 data['A+B'] = data['A'] + data['B'] # Final dataframe data = data[['A+B', 'A']] save_data = data.to_csv('/your_location/output.csv', sep = ';') data RE: huge and weird values after applying some calculations - sandeep_ganga - Dec-13-2019 tested with round(2) for data['A'], data['B'] and also for after addition, data['A+B'], now the data looks good on output file. import pandas as pd # Read the file data = pd.read_csv('for_test.csv', sep = ';') # Set the index data = data.set_index('Date_Time') # Drop the duplicated rows data = data.drop_duplicates(keep = "first") print(data) # Create new columns using Addition and Multiplication data['a1'] = data['x1'] * data['y1'] data['a2'] = data['x2'] * data['y2'] data['a3'] = data['x3'] * data['y3'] data['b1'] = data['x1'] * data['z1'] data['b2'] = data['x2'] * data['z2'] data['b3'] = data['x3'] * data['z3'] data['A'] = (data['a1'] + data['a2'] + data['a3']) * 0.01 data['B'] = (data['b1'] + data['b2'] + data['b3']) * 0.01 #new added below two and another one for data['A+B'].round(2) data['B']=data['B'].round(2) data['A']=data['A'].round(2) data['A+B'] = data['A'] + data['B'] data['A+B']=data['A+B'].round(2) # Final dataframe data = data[['A+B', 'A']] save_data = data.to_csv('output.csv', sep = ';') print(data)Best Regards, Sandeep GANGA SANDEEP KUMAR RE: huge and weird values after applying some calculations - karlito - Dec-13-2019 (Dec-13-2019, 02:21 AM)sandeep_ganga Wrote: tested with round(2) for data['A'], data['B'] and also for after addition, data['A+B'], now the data looks good on output file. The majority of the values in the B Column have been changed but there are others values specially being still formatted as "Jun+year" (Jun94, Jun97, Jun93) |