Placement 2025 Scholarship: Your Future Starts Here | 6 Guaranteed Job Interviews | Limited to 100 seats. Apply Now

00D 00H 00M 00S

Menu

Executive Programs

Workshops

Projects

Blogs

Careers

Placements

Student Reviews


For Business


More

Academic Training

Informative Articles

Find Jobs

We are Hiring!


All Courses

Choose a category

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

All Courses

All Courses

logo

CHOOSE A CATEGORY

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

Top Job Leading Courses

Automotive

CFD

FEA

Design

MBD

Med Tech

Courses by Software

Design

Solver

Automation

Vehicle Dynamics

CFD Solver

Preprocessor

Courses by Semester

First Year

Second Year

Third Year

Fourth Year

Courses by Domain

Automotive

CFD

Design

FEA

Tool-focused Courses

Design

Solver

Automation

Preprocessor

CFD Solver

Vehicle Dynamics

Machine learning

Machine Learning and AI

POPULAR COURSES

coursePost Graduate Program in Hybrid Electric Vehicle Design and Analysis
coursePost Graduate Program in Computational Fluid Dynamics
coursePost Graduate Program in CAD
coursePost Graduate Program in CAE
coursePost Graduate Program in Manufacturing Design
coursePost Graduate Program in Computational Design and Pre-processing
coursePost Graduate Program in Complete Passenger Car Design & Product Development
Executive Programs
Workshops
For Business

Success Stories

Placements

Student Reviews

More

Projects

Blogs

Academic Training

Find Jobs

Informative Articles

We're Hiring!

phone+91 9342691281Log in
  1. Home/
  2. ARAVIND M/
  3. Week 6 - Data analysis

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…

  • PYTHON
  • 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 the import matplotlib.pyplot and import numpy module.

                 import matplotlib.pyplot as plt

                 import numpy as np

  • Then for the compatibility check we use try and except loop.

           try:

                 open('engine_data.out')

                 print ('File open Successfully')

          except:

                 print('File not recognized please provide a valid files')

  • Then open command is used to open the file that provided.

                  for line in open('engine_data.out'):

  • To read the column number, column name, column units I have used for and if else loop.
  • For plotting graph I have used repl by input command to get the data he wants and convert the values into an integer by int command.

                  First_column = input('Please enter the value for X-axis = ')

                  x_axis = (int(First_column)-1)

  • The x-axis and y-axis are stored in an array using append and by converting the string into float.

                  value_of_x_axis.append(float(line.split()[x_axis]))

  • Then plot the graph using plt.plot.
  • The area of p-v curve is defined by storing the values in null array by append command.
  • The area is calculated by using np.trapz command.
  • Then the power, number of cycles per second, and fuel consumption are calculated using the formulas given in the program.

                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.

Please  login to add a comment

Other comments...

No comments yet!
Be the first to add a comment

Read more Projects by ARAVIND M (61)

Week 6 - Data analysis

Objective:

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…

calendar

25 Apr 2021 01:56 PM IST

  • PYTHON
Read more

Week 5 - Curve fitting

Objective:

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…

calendar

25 Apr 2021 01:25 PM IST

  • PYTHON
Read more

Week 3 - Solving second order ODEs

Objective:

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,…

calendar

19 Apr 2021 02:55 PM IST

  • PYTHON
Read more

Week 2 Air standard Cycle

Objective:

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…

calendar

13 Apr 2021 01:33 PM IST

  • PYTHON
Read more

Schedule a counselling session

Please enter your name
Please enter a valid email
Please enter a valid number

Related Courses

coursecard

Core and Advanced Python Programming

4.8

30 Hours of Content

coursecard

Applying CV for Autonomous Vehicles using Python

Recently launched

21 Hours of Content

coursecardcoursetype

Mechanical Engineering Essentials Program

4.7

21 Hours of Content

coursecardcoursetype

Internal Combustion Engine Analyst course using Python and Cantera

4.8

22 Hours of Content

coursecard

Computational Combustion Using Python and Cantera

4.9

9 Hours of Content

Schedule a counselling session

Please enter your name
Please enter a valid email
Please enter a valid number

logo

Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.

https://d27yxarlh48w6q.cloudfront.net/web/v1/images/facebook.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/insta.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/twitter.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/youtube.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/linkedin.svg

Our Company

News & EventsBlogCareersGrievance RedressalSkill-Lync ReviewsTermsPrivacy PolicyBecome an Affiliate
map
EpowerX Learning Technologies Pvt Ltd.
4th Floor, BLOCK-B, Velachery - Tambaram Main Rd, Ram Nagar South, Madipakkam, Chennai, Tamil Nadu 600042.
mail
info@skill-lync.com
mail
ITgrievance@skill-lync.com

Top Individual Courses

Computational Combustion Using Python and CanteraIntroduction to Physical Modeling using SimscapeIntroduction to Structural Analysis using ANSYS WorkbenchIntroduction to Structural Analysis using ANSYS Workbench

Top PG Programs

Post Graduate Program in Hybrid Electric Vehicle Design and AnalysisPost Graduate Program in Computational Fluid DynamicsPost Graduate Program in CADPost Graduate Program in Electric Vehicle Design & Development

Skill-Lync Plus

Executive Program in Electric Vehicle Embedded SoftwareExecutive Program in Electric Vehicle DesignExecutive Program in Cybersecurity

Trending Blogs

Heat Transfer Principles in Energy-Efficient Refrigerators and Air Conditioners Advanced Modeling and Result Visualization in Simscape Exploring Simulink and Library Browser in Simscape Advanced Simulink Tools and Libraries in SimscapeExploring Simulink Basics in Simscape

© 2025 Skill-Lync Inc. All Rights Reserved.

              Do You Want To Showcase Your Technical Skills?
              Sign-Up for our projects.