Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Sunday, 12 January 2020

Python 🐍 Plots

A plot is a visual representation of the data and is especially valuable to analyze data graphically. You can plot with the matplotlib package. In the incubator example, we may want to see how the temperature changes with time. The x-axis may be time and y-axis may be the data. In an incubator, graphs could be used for a number of things. Some could be heater percentage, egg temperature, and much more.

IPython Notebooks on Github: https://github.com/APMonitor/begin_py...

Tuesday, 7 January 2020

Begin Python 🐍 for and while loops

There are two basic types of loops including for and while. A for loop is to repeat code a predetermined number of times. A while loop is to repeat code but where the stopping condition may not be known before the loop starts.

Source code: https://github.com/APMonitor/begin_py...

Monday, 6 January 2020

Begin Python 🐍 Course Introduction

Welcome to this introductory course on Python! This course is intended to help you start programming in Python from little or no prior experience. There are video tutorials for each exercise if you have questions along the way. One of the unique things about this course is that you work on basic elements to help you with a temperature control project. You will see your Python code have a real effect by adjusting heaters to maintain a target temperature, just like a thermostat in a home or office.

One of the best ways to start or review a programming language is to work on a simple project. These exercises are designed to teach basic Python programming skills to help you design a temperature controller. Temperature control is found in many applications such as home or office HVAC, manufacturing processes, transportation, and life sciences. Even our bodies regulate temperature to a specific set point. This project is to regulate the temperature of the TCLab. Each TCLab has thermochromic (changes color with temperature) paint that turns from black to purple when the temperature reaches the target temperature of 37°C (99°F).

Final Project Objective: Program the TCLab to maintain the temperature at 37°C. Display the heater level with an LED indicator as the program is adjusting the temperature. Create a plot of the temperature and heater values over a 10 minute evaluation period.

To make the problem more concrete, suppose that you are designing a chicken egg incubator. Temperature, humidity, and egg rotation are all important to help the chicks develop. For this exercise, you will only focus on temperature control by adjusting the heater.

There are 12 lessons to help you with the objective of designing the temperature control for the incubator. The first thing that you will need is to install Anaconda to open and run the IPython notebook files in Jupyter. Any Python distribution or Integrated Development Environment (IDE) can be used (IDLE (python.org), Spyder, PyCharm, and others) but Jupyter notebook is required to open and run the IPython notebook (.ipynb) files.

Install Anaconda (Python): https://www.anaconda.com/distribution/

All of the IPython notebook (.ipynb) files can be downloaded at this link. Don't forget to unzip the folder (extract the archive) and copy it to a convenient location before starting. The course is freely available for download with course files on Github: https://github.com/APMonitor/begin_py...

1. Overview
2. Debugging
3. Variables
4. Printing
5. Classes and Objects
6. Functions
7. Loops
8. Input
9. If Statements
10. Lists and Tuples
11. Dictionaries
12. Plotting

You will also need a TCLab kit to complete the exercises and they are available for purchase on Amazon: https://www.amazon.com/gp/product/B07...

More information on the temperature control lab: https://apmonitor.com/heat.htm

Begin Python 🐍 Overview and pip install

This introductory course uses the TCLab package that can be installed with:

pip install tclab

or:

!pip install tclab --user

if you are running in a Jupyter notebook and do not have administrative privilege. The 12 modules of this course are intended to help you complete the final project.

Final Project: You have eggs that need to hatch in an incubator. One option is to constantly check the temperature and adjust the heaters manually. Another way is to automate the temperature control by constantly checking the temperature and adjusting the heaters with Python. Unfortunately, you only get three eggs for the test and one attempt to get it right. You do have a simulator of the incubator (TCLab) so you can practice Python, without having to worry about mistakes. The purpose of this lab is to develop a temperature controller (like a thermostat) that could be used for an egg incubator. There are other factors such as humidity and turning the eggs that are important with incubators but we'll only focus on the temperature for this project.

Source files: https://github.com/APMonitor/begin_py...

Begin Python 🐍 Pseudo-Code and Debugging

One of the biggest time consuming parts of programming is debugging, or resolving mistakes in the program. This is true for every language because the computer needs exact commands, which is very important for precise measurements and control for incubating. A few steps can limit the time you are searching for mistakes, instead of completing the project.

1. Start with understanding the big picture. It seems silly, but once you start going over the whole thing you find a lot of gaps. Do this in whichever way suits you best, we’ll leave it up to you. For the egg incubator, it would be understanding what you actually need to do to help an egg hatch.

2. Start by outlining your code, writing **high-level instructions (pseudo-code)** what you want each section of the code to do. Break it into more specific tasks. You can do this even without understanding the basics of Python. Once you learn Python basics, you can translate these high level instructions into code. Organizing the outline helps to make sure your programming isn't more complex than it needs to be.

3. Program the specific tasks and connect them together. Direct tasks make it significantly easier to program because the program is modular. It’s a lot harder to program something if the program is large and complex. For the incubator, this may be programming something specific like how hard the heater should work, based on a low temperature reading.

4. Test and fix problems. This is basically debugging, but don’t only test the whole project all in one go. It’s much easier to find a problem if you test every once in a while, when you are programming smaller parts. A good way to do this is grab a specific piece of code, run it on a seperate file, and see if it does the job you want. An example would be fixing when the heater should stop working, so the egg doesn't go over temperature.

The better you follow these steps the less time you will have to spend fixing problems in your code for your incubator, or just Python programs in general.

Begin Python 🐍 integer, string, float

Variables store information and are objects in Python. For example, if you wanted to keep a set temperature for an egg, you would type egg = 37.5 for °C or egg = 99.5 for °F. The first part tells what the variable will be called, and the value after the = tells what is being stored.

See https://github.com/APMonitor/begin_py... for source files.

Begin Python 🐍 print

Printing is displaying values to the screen. The word print comes from the time when programs previously put ink on paper. You use the built in python function print() to output values. You could use this to tell you what is the current temperature from a temperature sensor.

See https://github.com/APMonitor/begin_py... for source files.

Begin Python 🐍 Classes and Objects

Classes are collections of objects and functions. Many Python packages such as time, tclab, numpy, scipy, gekko, and others are distributed as classes. A class is imported with the import statement such as import time. Time is a package that has timing functions that we will use to pause the program for a specified amount of time. TCLab package has functions created with tclab.TCLab(). The next lesson shows how to use the tclab functions.

Source files: https://github.com/APMonitor/begin_py...

Begin Python🐍 functions

Functions create modular code that can do the same task repeatedly without you having to type out the same code each time. Functions make complex code accessible with a single statement. You also can create your own function, but there are also some are built in to Python or in many packages. One built in function you have already seen is the print() function.

Source code: https://github.com/APMonitor/begin_py...

Saturday, 7 December 2019

Python Vs R for Data Science - One Clear Winner

This video titled "Python Vs R for Data Science One Clear Winner" explains and compare both R and Python language on seven parameters when it comes to machine learning. Although both of these languages have their own strengths and weakness yet we will choose a clear winner based on these parameters.




Sunday, 3 November 2019

Thursday, 16 May 2019

Redirect and Errors

Flask class has a redirect() function. When called, it returns a response object and redirects the user to another target location with specified status code.
Prototype of redirect() function is as below −
Flask.redirect(location, statuscode, response)

In the above function − 1.location parameter is the URL where response should be redirected. 2.statuscode sent to browser’s header, defaults to 302. 3.response parameter is used to instantiate response.

The following status codes are standardized − 1.HTTP_300_MULTIPLE_CHOICES 2.HTTP_301_MOVED_PERMANENTLY 3.HTTP_302_FOUND 4.HTTP_303_SEE_OTHER 5.HTTP_304_NOT_MODIFIED 6.HTTP_305_USE_PROXY 7.HTTP_306_RESERVED 8.HTTP_307_TEMPORARY_REDIRECT
The default status code is 302, which is for ‘found’. In the following example, the redirect() function is used to display the login page again when a login attempt fails.
from flask import Flask, redirect, url_for, render_template, request # Initialize the Flask application

app = Flask(__name__) @app.route('/') def index(): return render_template('log_in.html') @app.route('/login',methods = ['POST', 'GET']) def login(): if request.method == 'POST' and request.form['username'] == 'admin' : return redirect(url_for('success')) return redirect(url_for('index')) @app.route('/success') def success(): return 'logged in successfully' if __name__ == '__main__': app.run(debug = True)
Flask class has abort() function with an error code. Flask.abort(code)
The Code parameter takes one of following values − 1.400 − for Bad Request 2.401 − for Unauthenticated 3.403 − for Forbidden 4.404 − for Not Found 5.406 − for Not Acceptabl 6.415 − for Unsupported Media Type 7.429 − Too Many Requests

Let us make a slight change in the login() function in the above code. Instead of re-displaying the login page, if ‘Unauthourized’ page is to be displayed, replace it with call to abort(401).
from flask import Flask, redirect, url_for, render_template, request, abort

app = Flask(__name__) @app.route('/') def index(): return render_template('log_in.html') @app.route('/login',methods = ['POST', 'GET']) def login(): if request.method == 'POST': if request.form['username'] == 'admin' : return redirect(url_for('success')) else: abort(401) else: return redirect(url_for('index')) @app.route('/success') def success(): return 'logged in successfully' if __name__ == '__main__': app.run(debug = True)

Thursday, 2 May 2019

Finding a Year is leap or not in Python

@author python.learning
>>> def check_year(year):
...      if year%4==0 and year%100!=0 or year%400==0:
...            print ('leap year')
...      else:
               print ('not a leap year')
>>>  check_year(1972)
leap year
>>>  check_year(1975)
not a leap year



# or check with calendar
>>> import calendar
>>> print (calendar.isleap(1972) )
True
>>> print (calendar.isleap(1975) )
False

Sunday, 24 March 2019

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and Java Script by Harry J.W.Percival (Author)

By taking you through the development of a real web application from beginning to end, the second edition of this hands-on guide demonstrates the practical advantages of test-driven development (TDD) with Python. YouΓ­ll learn how to write and run tests before building each part of your app and then develop the minimum amount of code required to pass those tests. The result? Clean code that works.
In the process, youΓ­ll learn the basics of Django, Selenium, Git, jQuery and Mock, along with current web development techniques. If youΓ­re ready to take your Python skills to the next level, this bookΓ³updated for Python 3.6Γ³clearly demonstrates how TDD encourages simple designs and inspires confidence.

Dive into the TDD workflow, including the unit test/code cycle and refactoring
Use unit tests for classes and functions and functional tests for user interactions within the browser
Learn when and how to use mock objects and the pros and cons of isolated vs. integrated tests
Test and automate your deployments with a staging server
Apply tests to the third-party plugins you integrate into your site
Run tests automatically by using a Continuous Integration environment
Use TDD to build a REST API with a front-end Ajax interface 


Buy :

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and Java Script Paperback – 2017 by Harry J.W.Percival (Author) 

PDF Download :

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and Java Script Paperback – 2017 by Harry J.W.Percival (Author) 




Programming with MicroPython by Nicholas H. Tollervey (Author)

It's an exciting time to get involved with MicroPython, the re-implementation of Python 3 for microcontrollers and embedded systems. This practical guide delivers the knowledge you need to roll up your sleeves and create exceptional embedded projects with this lean and efficient programming language. If you're familiar with Python as a programmer, educator, or maker, you're ready to learn-and have fun along the way.

 Author Nicholas Tollervey takes you on a journey from first steps to advanced projects. You'll explore the types of devices that run MicroPython, and examine how the language uses and interacts with hardware to process input, connect to the outside world, communicate wirelessly, make sounds and music, and drive robotics projects. Work with MicroPython on four typical devices: PyBoard, the micro:bit, Adafruit's Circuit Playground Express, and ESP8266/ESP32 boards Explore a framework that helps you generate, evaluate, and evolve embedded projects that solve real problems Dive into practical MicroPython examples: 

visual feedback, input and sensing, GPIO, networking, sound and music, and robotics Learn how idiomatic MicroPython helps you express a lot with the minimum of resources Take the next step by getting involved with the Python community

Buy :

Programming with MicroPython Paperback – 6 Oct 2017 by Nicholas H. Tollervey (Author) 

PDF Download :

Programming with MicroPython Paperback – 6 Oct 2017 by Nicholas H. Tollervey (Author) 




Saturday, 23 March 2019

Mastering Python for Data Science Paperback – Import, 31 Aug 2015 by Samir Madhavan (Author)

If you are a Python developer who wants to master the world of data science, then this book is for you. Some knowledge of data science is assumed.

Buy :

Mastering Python for Data Science Paperback – Import, 31 Aug 2015 by Samir Madhavan (Author) 

PDF Download :

Mastering Python for Data Science Paperback – Import, 31 Aug 2015 by Samir Madhavan (Author) 


Friday, 22 March 2019

Numerical Python: A Practical Techniques Approach for Industry 1st Edition, Kindle Edition by Robert Johansson (Author)

Numerical Python by Robert Johansson shows you how to leverage the numerical and mathematical modules in Python and its Standard Library as well as popular open source numerical Python packages like NumPy, FiPy, matplotlib and more to numerically compute solutions and mathematically model applications in a number of areas like big data, cloud computing, financial engineering, business management and more.
After reading and using this book, you'll get some takeaway case study examples of applications that can be found in areas like business management, big data/cloud computing, financial engineering (i.e., options trading investment alternatives), and even games.
Up until very recently, Python was mostly regarded as just a web scripting language. Well, computational scientists and engineers have recently discovered the flexibility and power of Python to do more. Big data analytics and cloud computing programmers are seeing Python's immense use. Financial engineers are also now employing Python in their work. Python seems to be evolving as a language that can even rival C++, Fortran, and Pascal/Delphi for numerical and mathematical computations. 

Buy :


PDF Download :


Tuesday, 19 March 2019

Python for Data Mining Quick Syntax Reference Paperback – Import, 20 Dec 2018 by Valentina Porcu (Author)

Learn how to use Python and its structures, how to install Python, and which tools are best suited for data analyst work. This book provides you with a handy reference and tutorial on topics ranging from basic Python concepts through to data mining, manipulating and importing datasets, and data analysis.

Python for Data Mining Quick Syntax Reference covers each concept concisely, with many illustrative examples. You'll be introduced to several data mining packages, with examples of how to use each of them. 

The first part covers core Python including objects, lists, functions, modules, and error handling. The second part covers Python's most important data mining packages: NumPy and SciPy for mathematical functions and random data generation, pandas for dataframe management and data import, Matplotlib for drawing charts, and scikitlearn for machine learning.  

What You'll Learn
  • Install Python and choose a development environment
  • Understand the basic concepts of object-oriented programming
  • Import, open, and edit files
  • Review the differences between Python 2.x and 3.x
Who This Book Is For

Programmers new to Python's data mining packages or with experience in other languages, who want a quick guide to Pythonic tools and techniques.
 
Buy :
PDF Download :
 

Friday, 15 March 2019

Serious Python: Black-Belt Advice on Deployment, Scalability, Testing, and More

An indispensable collection of practical tips and real-world advice for tackling common Python problems and taking your code to the next level. Features interviews with high-profile Python developers who share their tips, tricks, best practices, and real-world advice gleaned from years of experience.

Sharpen your Python skills as you dive deep into the Python programming language with Serious Python. You'll cover a range of advanced topics like multithreading and memorization, get advice from experts on things like designing APIs and dealing with databases, and learn Python internals to help you gain a deeper understanding of the language itself. Written for developers and experienced programmers, Serious Python brings together over 15 years of Python experience to teach you how to avoid common mistakes, write code more efficiently, and build better programs in less time.

As you make your way through the book's extensive tutorials, you'll learn how to start a project and tackle topics like versioning, layouts, coding style, and automated checks. You'll learn how to package your software for distribution, optimize performance, use the right data structures, define functions efficiently, pick the right libraries, build future-proof programs, and optimize your programs down to the bytecode. You'll also learn how to:

- Make and use effective decorators and methods, including abstract, static, and class methods
- Employ Python for functional programming using generators, pure functions, and functional functions
- Extend flake8 to work with the abstract syntax tree (AST) to introduce more sophisticated automatic checks into your programs
- Apply dynamic performance analysis to identify bottlenecks in your code
- Work with relational databases and effectively manage and stream data with PostgreSQL

If you've been looking for a way to take your Python skills from good to great, Serious Python will help you get there. Learn from the experts and get seriously good at Python with Serious Python!


Buy :

Serious Python: Black-Belt Advice on Deployment, Scalability, Testing, and More Paperback – Import, 27 Dec 2018 by Julien Danjou 

PDF Download :

Serious Python: Black-Belt Advice on Deployment, Scalability, Testing, and More Paperback – Import, 27 Dec 2018 by Julien Danjou 


Thursday, 14 March 2019

Classic Computer Science Problems in Python

Classic Computer Science Problems in Python presents dozens of coding challenges, ranging from simple tasks like finding items in a list with a binary sort algorithm to clustering data using k-means.

Classic Computer Science Problems in Python deepens your Python language skills by challenging you with time-tested scenarios, exercises, and algorithms. As you work through examples in search, clustering, graphs, and more, you'll remember important things you've forgotten and discover classic solutions to your "new" problems

Key Features
·   Breadth-first and depth-first search algorithms
·   Constraints satisfaction problems
·   Common techniques for graphs
·   Adversarial Search
·   Neural networks and genetic algorithms
·   Written for data engineers and scientists with experience using Python.
For readers comfortable with the basics of Python

About the technology
Python is used everywhere for web applications, data munging, and powerful machine learning applications. Even problems that seem new or unique stand on the shoulders of classic algorithms, coding techniques, and engineering principles. Master these core skills, and you’ll be ready to use Python for AI, data-centric programming, deep learning, and the other challenges you’ll face as you grow your skill as a programmer.

David Kopec teaches at Champlain College in Burlington, VT and is the author of Manning’s Classic Computer Science Problemsin Swift.

Buy :

Classic Computer Science Problems in Python 

PDF Download :

Classic Computer Science Problems in Python 



Popular Posts

Categories

Android (21) AngularJS (1) Books (3) C (75) C++ (81) Data Strucures (4) Engineering (13) FPL (17) HTML&CSS (38) IS (25) Java (85) PHP (20) Python (94) R (69) Selenium Webdriver (2) Software (13) SQL (27)