Sending print statements to the console is very common in Python coding. It is simply a matter of using the key word print, followed by what you want printed to the screen. For example: # variables year = ‘2015’ xldate = 41000 pvid_list = [“19615056”, “15612770”, “15612771”] # print a raw string print “Print this … Continue reading Python: How to use the logging module
Python
Python and PHP: A comparison of the language basics
In this table I will compare some basic programming syntax and conventions between the Python and PHP programming languages. Programming element Python PHP Code commenting PHP supports Python and JavaScript conventions # Single line comment “””This is a multi-line comment block. This is a multi-line comment block.””” # Single line comment // Single line comment/*This … Continue reading Python and PHP: A comparison of the language basics
Data Science: How to calculate confusion matrix
In Data Science, the confusion matrix is a measure of the health of a model. In particular, it helps to measure the performance of a supervised learning model. For this article, I will detail how to create a confusion matrix for a binary classification model both manually and using an sklearn built-in function called metrics.confusion_matrix. … Continue reading Data Science: How to calculate confusion matrix
Python and Ruby: A comparison of the language basics
In this table I will compare some basic programming syntax and conventions between the Python and Ruby programming languages. Programming element Python Ruby Commenting code: Both use the pound # sign. # This is a comment # This is a comment Multi-line comments: “”” This is a comment. This is a comment, too. This is … Continue reading Python and Ruby: A comparison of the language basics
Data Mining Tools: Row to Array
This article is the second in a series of articles about data mining tools written in Python CGI that make common data mining tasks faster and easier. The first article in the series can be seen here: Data Mining Tools: Column to Array This tool is very similar to the previous tool, except it is … Continue reading Data Mining Tools: Row to Array
Data Mining Tools: Column to Array
I have created some Python tools that make data mining easier. For example, when moving lots of data around one thing that comes up often is getting information from a spreadsheet into a Python data container such as a list. This can be done by adding some code in a Python script to open an … Continue reading Data Mining Tools: Column to Array
Python: How to build a dictionary with two lists using zip( )
If you have two lists and would like to build a dictionary where one list will be the keys and the second list will be the values, Python has a way to do this easily using the built-inzip() function. With small enough examples, we could build our dictionary manually by typing it at the keyboard. … Continue reading Python: How to build a dictionary with two lists using zip( )
Python: How to read and write JSON
JSON is a lightweight data-interchange format that stands for JavaScript Object Notation. It so happens that JavaScript objects look exactly like Python dictionaries, so JSON objects can be thought of as portable dictionaries of key-value pairs. This portability is what makes JSON so valuable. While JSON objects can be identical to Python dictionaries, there are some … Continue reading Python: How to read and write JSON
Python: How to create GUI pop-up windows with Tkinter
When creating a program in Python, a useful thing to be able to do is to have a pop-up window appear on the screen with a special message. This can be used to give instant feedback to the user, alert the user to an error, or inform the user that the program completed successfully. In … Continue reading Python: How to create GUI pop-up windows with Tkinter
Python and JavaScript: A comparison of the language basics
In this table I will compare some basic programming syntax and conventions between the Python and JavaScript programming languages. Programming element Python JavaScript Creating a variable that contains an int: age = 25 var age = 25; Creating a variable that contains a float: probability = 0.62 var probability = 0.62; Creating a variable that … Continue reading Python and JavaScript: A comparison of the language basics