Category: Python

Python code examples

Django – Making a simple web app with 4 links

The idea of the article is to show how to make a simple Django App, with 4 links, each of which navigates to a specific page. The whole code of the “app” is in GitHub, here: https://github.com/Vitosh/Python_personal/tree/master/JustProject. In general, these are

Tagged with: , , , , , , ,

Python – Exception handling

Exception handling in python is actually quite an interesting topic. In general, the exceptions in programming could be of three types: syntactic errors – these would be noticed by your IDE or by the interpretor, thus you do not need

Tagged with: , , ,

Using API calls with VBA and Python to Read and Write to a Database

Using API calls with VBA and Python to write a database is actually a pretty decent architecture. Here, I would like to say that “It takes the best of the both worlds”, but the truth is that it takes the

Tagged with: , , , , , , , ,

Python – Virtual Environment

This is a short step-by-step introduction on how to build virtual environment in Python and how to use it. Virtual envirnments keep dependencies, required by the specific project separated. Thus, it is the “clean and clear” place of the project,

Tagged with: , , ,

Python – Django Girls – Introduction to Django – Video

Months ago, I was planning to take part in the #RailGirls event in Sofia, and I was even a partner in the event. Anyway, as it was postponed up to somewhere in the future, I have decided to go through

Tagged with: , , ,

Python – Writing Unit Tests with unittest library – Video

In the previous article for abstraction and inheritance I wrote some classes, showing the basics of these two programming concepts. In this one, I will write unit tests for one of the classes, written before. Software testing is an important

Tagged with: , , , , , ,

Python – Abstraction and Inheritance – Video

Abstract classes in Python are classes that inherit from the ABC (Abstract base class). In the video below, I have solved a problem, showing how 2 classes inherit from an abstract class and implement its methods. The abstract class is

Tagged with: , ,

Python – Closure

In this article I am planning to give an answer of the following two questions: What is a closure? A closure is a function, inheriting variables from enclosing environment. Operationally, a closure is a record storing a function together with

Tagged with: , ,

Python – Abstract Methods and Abstract Class – Live Coding Video

Abstract class and abstract methods are one of the pillars of Object Oriented Programming. In Python, an abstract class is a class, inheriting from Abstract Base Classes (ABC) library. And an abstract method is a method of this class, which

Tagged with: , , ,

Python – Permutations and Combinations Made Easy with Itertools

Long time ago, various people, including me, were trying to make permutations and combinations with nested loops and various other “heavy” structures. Anyway, in Python there is a library, which does this for us and sets the end of the

Tagged with: , , , ,

Python – Defining Classes and Methods with Python – LiveCoding Video

Today I have decided to check whether I can pass the first homework from SoftUni OOP with Python, through a live coding session. I have not read the problem before the video, thus I may say it took me exactly

Tagged with: , , , , ,

Python – Making Maps with Cartopy

Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses. Making a map with Python and Cartopy is actually easier than you might think, but still it has its own

Tagged with: , , , , , ,

Python – Bayes’ theorem – Drug testing example. 99% is not enough!

The Bayes’ theorem is interesting, as far as it is both quite challenging to understand and shocking once you really realize the simplicity of the numbers behind it. It describes the probability of an event, based on prior knowledge of conditions that

Tagged with: , , , ,

Python – Linear Regression

In 2013 and 2014 (wow, already 7 years ago!) I wrote two articles about linear regression with Excel. Now, I am getting more and more interested in Python, thus I guess it would be interesting to remake the article into

Tagged with: , , , ,

Python – Building New Columns in a Dataframe, Based on Other Columns

Working with python, pandas and dataframes is quite challenging even for experienced Excel & VBA developer, as I love to consider myself for one. Thus, today I was fighting for quite some time to add new columns to a dataframe,

Tagged with: , , , , , , , ,

Python – *args, **kwargs and the normal ones (arg)

The good, the bad and the ugly is a famous western. In Python, “the ugly” is probably the **kwargs, as far as it has two stars before it. Anyhow, the idea of *args, **kwargs and arg is simply to pass arguments.

Tagged with: , , , , , ,

Python – List Comprehension

List comprehension in Python is creation of lists from iterables and other lists, following a condition. It is lightning fast and it looks nice, because it is a 1 liner. In this article, I will show a few examples of

Tagged with: , , , , ,

Python – What is the idea of “-1” in numpy reshape?

Today I was “fighting” with the numpy reshape function and I found something strange like matrix.reshape(1, -1). Thus, I have researched quite some time and I found, that the -1 is actually a placeholder for python to change the dimensions of

Tagged with: , , ,

Python – How to write string into a matrix. Printing a matrix.

Writing string into a matrix seems like a non-interesting and somehow trivial task. Anyway, manipulating with matrices and strings in Python is actually somehow interesting, thus I have decided to present a small algorithmic challenge.  The task is pretty much

Tagged with: , , , , ,

Python – UnitTests in Jupyter Notebook

Unit testing is the “sweet” part of the programming – once you have tested “all the things”, you feel that the code you have submitted somewhere is actually valid and somehow it works. Furthermore, it allows you to nicely brag

Tagged with: , , , , ,

Python – Statsmodels Example – Video

Statsmodels is a nice statistics library in Python, which eases the data processing and analysis with Python. The library is available here – statsmodels.org and on its official web site the installation guide is always up to date. In the

Tagged with: , ,

Excel – How to build magic square with VBA, following Python Mod Mathematics

Some 4 years ago I wrote an article for calculating magic square with python. What the article did was actually checking whether the square is magic, and not calculating a new one. This one is going to show how these

Tagged with: , , ,

Python – Plotting DataFrame and Working with Pandas – Video

Working with Pandas is like working with Excel on steroids – it can really do a lot of things fast, but somehow doing the easy things get complicated. In this video and article tutorial I am presenting loading data to

Tagged with: , , , , , , ,

Cryptography in Python

ModernPythonStandardLibraryBook

After writing about hashing passwords in Python, I have decided to publish the other parts of the chapter, “Cryptography” from the “Modern Python Standard Library Cookbook“, written by Alessandro Molina and and kindly provided to me by PacktPublishing.In the article,

Tagged with: , , , , , , , , , ,

Python – Platforms Jumping – CodeForces

Greedy algorithm is described as an algorithm that follows the problem-solving heuristic of making the locally optimal choice at each stage with the intent of finding a global optimum. Thus, it is always interesting to find a problem, which can

Tagged with: , , ,

Python Slice Notation

Python Slice Notation is somehow easy and tough in the same way. Lately, I was doing some competitive programming with Python and I have decided to write a summary of the slice notation, thus there is always a place for

Tagged with: , , , , , , ,

Python – Binary String Minimizing Problem – CodeForces

Codeforces has introduced a third division in their competitions. Initially I though this is the place to go for “easy” stuff, as far as some of the 2nd division problems require some advanced algorithms, like combinations of graphs and months

Tagged with: , , , , ,

Find all list (li) elements in a special position of a web site

So, my idea was to obtain all the elements, tagged with “li” from here – vitoshacademy.com/all, using BeautifulSoup4 and Python. Initially, I thought about running a simple soup.findAll("li") , but it also added the text from the menus, which were

Tagged with: , , , ,

Scraping a web site up to the N-th level with Python

Scraping data from a web site has always been a pleasure with Python. If you come from the VBA world, the BeautifulSoup4 is indeed beautiful! I have been scraping a web site with python before, but now as I have

Tagged with: , , , ,

Prime numbers matrix and coloring with Python and xlsxwriter

About 4 years ago, I wrote an article about prime numbers in Excel and their visualisation with VBA – vba-function-in-excel-to-check-prime-numbers. Pretty much, it displays the prime numbers in a 10 x N matrix, starting from 1 and finishing at N:

Tagged with: , , , , , , , , , ,
Top