Found 10784 Articles for Python

Working with PDF files in Python?

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

1K+ Views

Python is a very versatile language as it provides huge set of libraries to work on different requirements. We all work on Portable Document Format (PDF) files. Python provides different ways to work with pdf files. In this we are going to use python library called PyPDF2 to work with pdf file.PyPDF2 is a pure-python PDF library capable of splitting, merging together, cropping, and transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF files. It can retrieve text and metadata from PDFs as well as merge entire files together.As we can ... Read More

Junk File Organizer in Python?

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

416 Views

This might seem very useful for a lazy python programmer who keeps most of the files and folders at one location and sometimes at confused what all files are there and surely he is too lazy to do it manually. So below is a python program to organize or simplify everything in appropriate folder in the single go and remove empty directories.So we have a directory path where lots of files of different types are present (like below) and our program we segregate each file type into their respective folders (like below).Input folder structureDesired OutputFirst create different folders based on ... Read More

Determine the type of an image in Python?

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

4K+ Views

In this section we are going to see the type of image file we have. So consider a situation, where in a directory we have hundreds of image file and we want to get all the jgeg(or any particular image file type) file type. All this we are going to do programmatically using python.Python provide library to determine the type of an image, on such library is imghdr.The python imghdr package determines the type of image contained in a file or byte stream.InstallationThere is a very much chances that if you are using python 3.6 or higher, imghdr module is ... Read More

Command Line Interface Programming in Python?

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

586 Views

In this section we are going to develop a command line interface using python. But before we deep dive into program, lets first understand command line.Command line are in use since the existence of computer programs and are built on commands. A command line program is a program that runs from a shell or from a command lineWhile command line interface provides user interface that is navigated by typing commands at terminals, shells or consoles instead of using the mouse.A command-line interface(CLI) starts with an executable. There are parameters which we can pass to the script depending how they are ... Read More

Understanding Logistic Regression in Python?

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

260 Views

Logistic Regression is a statistical technique to predict the binary outcome. It’s not a new thing as it is currently being applied in areas ranging from finance to medicine to criminology and other social sciences.In this section we are going to develop logistic regression using python, though you can implement same using other languages like R.InstallationWe’re going to use below libraries in our example program, Numpy: To define the numerical array and matrixPandas: To handle and operate on dataStatsmodels: To handle parameter estimation & statistical testingPylab: To generate plotsYou can install above libraries using pip by running below command in ... Read More

Hangman Game in Python?

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

497 Views

Hangman is a classic word game in which participants needs to guess as many secret words as you can before time runs out! So, it’s a nice game to learn new words, one letter at a time!So we are going to write python script for this classic game “hangman”.#importing the time module import time #welcoming the user name = input("What is your name? ") print("Hello, " + name, "Time to play hangman!") print ("") #wait for 1 second time.sleep(1) print ("Start guessing...") time.sleep(0.5) #here we set the secret word= ("Secret") word = word.lower() ... Read More

Python Rational numbers (fractions)

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

2K+ Views

Any number which can be expressed as a quotient or fraction in the form of p/q is called a rational number. The fractions module of Python library provides functionality for rational number arithmetic.This module defines a Fraction class. Its object can be constituted in various ways as below −Fraction(num, denom)The first version of Fraction constructor receives two parameters for numerator and denominator. Default numerator is 0 and default denominator is 1. Value of denominator = 0 throws ZeroDivisionError.>>> from fractions import Fraction >>> n1 = Fraction(2, 5) >>> n1 Fraction(2, 5) >>> n2 = Fraction(6, 15) >>> n2 Fraction(2, 5) ... Read More

Mathematical statistics functions in Python

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

459 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

195 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

616 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

Advertisements