Found 10805 Articles for Python

Mathematical statistics functions in Python

Samual Sam
Updated on 30-Jun-2020 12:48:26

416 Views

The statistics module of Python library consists of functions to calculate statistical formulae using numeric data types including Fraction and Decimal types.Following import statement is needed to use functions described in this article.>>> from statistics import *Following functions calculate the central tendency of sample data.mean() − This function calculates the arithmetic mean of data in the form of sequence or iterator.>>> from statistics import mean >>> numbers = [12, 34, 21, 7, 56] >>> mean(numbers) 26The sample data may contain Decimal object or Fraction object>>> from decimal import Decimal >>> numbers = [12, 34, 21, Decimal('7'), 56] >>> mean(numbers) Decimal('26') ... Read More

Calculate geographic coordinates of places using google geocoding API in Python?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

173 Views

To get the geographic coordinates of the place that is longitude and latitude of the place we can use google maps geocoding api.RequirementTo get the coordinates of a place, we required geocoding api & you can get it from below link:https://developers.google.com/maps/documentation/geocoding/get-api-keyApart from api_key, we are going to use pythonRequest module (fetch the coordinates)Json module (for conversion).Below is the program to achieve the same:# Import required library import requests import json #Enter the place name place = input("Please enter place name: ") #Place your google map API_KEY to a variable apiKey = 'YOUR_API_KEY' #Store google geocoding api url in a variable ... Read More

Calculate distance and duration between two places using google distance matrix API in Python?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

576 Views

We almost all use google maps to check distance between source and destination and check the travel time. For developers and enthusiasts, google provide ‘google distance matrix API’ to calculate the distance and duration between two places.To use google distance matrix api, we need google maps API keys, which you can get from below link:https://developers.google.com/maps/documentation/distance-matrix/get-api-keyRequired librariesWe can accomplish this by using different python library, like:PandasgooglemapsRequestsJsonI am using very basic requests and json library. Using pandas you can fill multiple source and destination places at a time and get the result in csv file.Below is the program to implement the same:# ... Read More

Python script to open a Google Map location on clipboard?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

815 Views

We generally open the browser to search for a specific site/place on google maps. And if you need to do this task multiple times a day, it becomes very boring. Now you can automate this task where your browser will open automatically and the webpage will show you the google maps of your desired location.InstallationFor this purpose, I’m going to use the paperclip package. As this is not the standard package, we need to install it using pip.>pip install pyperclip Collecting pyperclip Downloading https://files.pythonhosted.org/packages/2d/0f/4eda562dffd085945d57c2d9a5da745cfb5228c02bc90f2c74bbac746243/pyperclip-1.7.0.tar.gz Building wheels for collected packages: pyperclip Building wheel for pyperclip (setup.py) ... done Stored in directory: ... Read More

Plotting Data on Google Map using pygmaps package?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

299 Views

Python pygmaps library provides a wrapper for the google maps javascript api. With this library python users can create a matplotlib like interface to generate the html and javascript and then can depicts all the additional information user’s would like to add on top of Google Maps.Required libraryWe are only going to use the pygmaps library/package. You can install the pygmaps library using pip, like:$pip install pygmaps (windows os) $sudo pip3 install pygmaps (linux os)We are going to write a program which will display -Create a map using pygmaps by providing long, lat & zoom level.Set grids on map by ... Read More

Phyllotaxis pattern in Python?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

228 Views

What is phyllotaxis pattern?When we go back, in our botany classes and the plant world, phyllotaxis means the arrangement of flowers, leaves or seeds on a plant stem, similar to the one found in Fibonacci spiral. Based on Fibonacci sequence, the Fibonacci spiral is a set of numbers that follows a pattern similar on pascal’s triangle. The Fibonacci sequence numbers are something like - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, etc. So the Fibonacci sequence number is the sum of its previous numbers.Fibonacci spiralsWe generally look for symmetry and patterns to understand the objects ... Read More

WebCam Motion Detector program in Python ?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

240 Views

In this we are going to write python program which is going to analyse the images taken from the webcam and try to detect the movement and store the time-interval of the webcam video in a csv file.Required LibraryWe are going to use the OpenCV & pandas library for that. If it’s not already installed, you can install it using pip, with something like:$pip install opencv2, pandasExample Code#Import required libraries import cv2 import pandas as pd import time from datetime import datetime #Initialise variables stillImage = None motionImage = [ None, None ] time = [] # Initializing ... Read More

Fetch top 10 starred repositories of user on GitHub using Python?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

55 Views

Git is the most popular version control system, where millions of developers manage their project or files (code). In this we will try to fetch top 10 most starred repositories within a month.As we are mainly scraping the GitHub repositories, we are going to use mainly the, Requests & BeautifulSoup library to fetch the repositories.We will store the result in a file & display it. It will show the result based on position (stars) with name & repos.Below is the code to implement it:import requests from bs4 import BeautifulSoup r = requests.get('https://github.com/trending/lua?since=monthly') bs = BeautifulSoup(r.text, 'lxml') lista_repo = bs.find_all('ol', class_='repo-list') ... Read More

Conway’s Game Of Life using Python?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

445 Views

A British mathematician in an around 1970 created his “Game of Life” – which are basically a set of rules depicting the chaotic yet patterned growth of a colony of biological organisms. The “Game of Life” is a two-dimensional grid consists of “living” and “dead” cells.Rules of Game of lifeOverpopulation: A cell dies(off) if its surrounded by more than three living cells.Static: A cell lives(on) if its surrounded by two or three living cells.Underpopulation: A cell dies(off) if its surrounded by fewer than two living cells.Reproduction: A cell becomes live(on) if a dead cell is surrounded by exactly three cells. Cell ... Read More

Run Python script from Node.js using child process spawn() method?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

NodeJs and Python are two main preferred languages among developers and web designers. But there are couple of areas where NodeJs fall short of python are numerical and scientic computation (AI, Machine learning, deep learning etc.). Whereas python provides lots of libraries to work with scientific computing lot easier.Luckly, we can utilise the python libraries within our nodejs application by running python in the background and return back the result.For this we are going to use the child_process standard library of NodeJs to spawn a pyton process in the background, do computation and return back the result to our node ... Read More

Advertisements