Python Forum
huge and weird values after applying some calculations
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
huge and weird values after applying some calculations
#1
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 [Image: IKJr6go.png] and the pandas [Image: IKJrnpK.png] 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
Reply
#2
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
Reply
#3
(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.

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

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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Evaluate Calculations yrstruly 0 948 Jun-17-2023, 06:51 PM
Last Post: yrstruly
  [solved] how to speed-up huge data in an ascii file ? paul18fr 4 1,207 May-16-2023, 08:36 PM
Last Post: paul18fr
  Finding the median of a column in a huge CSV file markagregory 5 1,732 Jan-24-2023, 04:22 PM
Last Post: DeaD_EyE
  visualizing huge correation matrix erdemath 3 1,962 Oct-13-2021, 09:44 AM
Last Post: erdemath
  What to use with simple calculations Milfredo 6 2,603 Sep-24-2020, 06:42 AM
Last Post: Milfredo
  matplotlib.pyplot functions create new figures instead of applying to the current one karkas 2 2,043 Jul-09-2020, 08:32 AM
Last Post: karkas
  Applying operation to a pandas multi index dataframe subgroup Nuovoq 1 2,615 Sep-04-2019, 10:04 PM
Last Post: Nuovoq
  Applying Function With If ab0217 8 3,673 Jul-02-2019, 12:30 PM
Last Post: ichabod801
  Pandas .rolling() with some calculations inside irmscher 5 6,126 Apr-04-2019, 11:55 AM
Last Post: scidam
  Pandas, cryptocurrency and some calculations vvinni 0 1,990 Mar-10-2019, 03:52 PM
Last Post: vvinni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020