All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
DATA ANALYSIS USING PYTHON AIM In this challenge, we have to do data analysis for a given data using python and extract the data and graph that user want by REPL method. REPL REPL stands…
ARAVIND M
updated on 25 Apr 2021
DATA ANALYSIS USING PYTHON
AIM
In this challenge, we have to do data analysis for a given data using python and extract the data and graph that user want by REPL method.
REPL
REPL stands for read, Evaluate, Print, Loop. The REPL is how you interact with the Python Interpreter. Unlike running a file containing Python code, in the REPL you can type commands and instantly see the output printed out.
PROCEDURE
import matplotlib.pyplot as plt
import numpy as np
try:
open('engine_data.out')
print ('File open Successfully')
except:
print('File not recognized please provide a valid files')
for line in open('engine_data.out'):
First_column = input('Please enter the value for X-axis = ')
x_axis = (int(First_column)-1)
value_of_x_axis.append(float(line.split()[x_axis]))
No.of cycles = RPM/(2*60)
Power = No.of cycles * area
Specific fuel consumptions = fuel consumption per hour /power
PROGRAM
# File parsing in python
import math
import matplotlib.pyplot as plt
import numpy as np
# compability check
try:
open('engine_data.out')
print ('File open Successfully')
except:
print('File not recognized please provide a valid files')
# Reading file data
line_count = 1
headline_count=1
#File Parsing
for line in open('engine_data.out'):
if '#' not in line:
line_count=+1
column_count = len(line.split())
else:
headline_count=headline_count+1
if headline_count==3:
column_number=(line.split())
if headline_count==4:
column_name=(line.split())
if headline_count==5:
column_units=(line.split())
#print(column_count)
#print(column_number)
#print(column_name)
#print(column_units)
print('column parameters(1-17)','1:Crank,2:Pressure,3:Max_Pres,4:Min_Pres,5:Mean_Temp,6:Max_Temp,7:Min_Temp,8:Volume,9:Mass,10:Density,11:Integrated_HR,12:HR_Rate,13:C_p,14:C_v,15:Gamma,16:Kin_Visc,17:Dyn_Visc')
First_column = input('Please enter the value for X-axis = ')
x_axis = (int(First_column)-1)
Second_column = input('Please enter the value for y-axis = ')
y_axis = (int(Second_column)-1)
print('You are requested the graph between',column_name[(x_axis)+1],'vs',column_name[(y_axis)+1])
value_of_x_axis = []
value_of_y_axis = []
for line in open('engine_data.out'):
if '#' not in line:
value_of_x_axis.append(float(line.split()[x_axis]))
for line in open('engine_data.out'):
if '#' not in line:
value_of_y_axis.append(float(line.split()[y_axis]))
plt.plot(value_of_x_axis,value_of_y_axis)
plt.savefig(column_name[((x_axis)+1)]+'vs'+column_name[((y_axis)+1)]+'.png')
plt.xlabel(column_name[((x_axis)+1)]+column_units[((x_axis)+1)])
plt.ylabel(column_name[((y_axis)+1)]+column_units[((y_axis)+1)])
plt.show()
# For P-V diagram take volume and pressure null array
volume = []
pressure = []
for line in open('engine_data.out'):
if '#' not in line:
volume.append(float(line.split()[7]))
pressure.append(float(line.split()[1]))
#area under the P-V curve
area = np.trapz(pressure,volume)
# Work done per cycle
work_done = area
print('Total work done per cycle =', work_done,'MJ')
#RPM = 1500
RPM = input(' enter the RPM = ')
RPM = int(RPM)
# NUMBER OF CYCLES PER SECOND FOR 4 STROKE ENGINE
n = RPM/(2*60)
#Power of the engine
Power = area*n
print('The power of the engine =',Power,'MW')
# Calculating fuel consumption
fuel_consumption = input('Enter the fuel_consumption in micro gram = ')
fuel_consumption = int(fuel_consumption)
fuel_consumption_perhour = fuel_consumption*pow(10,-6)*RPM*60
specific_fuel_consumption = fuel_consumption_perhour/Power
print('specific_fuel_consumption = ',specific_fuel_consumption,'gram/MW.hr')
OUTPUT
CONCLUSION
Learned file parsing and data analysis using python and repl method.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 6 - Data analysis
DATA ANALYSIS USING PYTHON AIM In this challenge, we have to do data analysis for a given data using python and extract the data and graph that user want by REPL method. REPL REPL stands…
25 Apr 2021 01:56 PM IST
Week 5 - Curve fitting
CURVE FITTING USING PYTHON AIM In this challenge, we have to write a program for curve fitting using python. CURVE FITTING Curve fitting is the process of constructing…
25 Apr 2021 01:25 PM IST
Week 3 - Solving second order ODEs
SOLVING SECOND ORDER EQUATION USING PYTHONAIM Using second ODE to describe the transient behaviour of a system of simple pendulum on python scripting.OBJECTIVE In Engineering,…
19 Apr 2021 02:55 PM IST
Week 2 Air standard Cycle
AIR STANDARD CYCLE USING PYTHON AIM To write a program in python to solve the otto cycle and plot the graph. OBJECTIVE To solve different state variables in the otto cycle and plot p-v diagram. To calculate thermal efficiency for the given parameters in…
13 Apr 2021 01:33 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.