Posts

Plotting growth curve using python

Image
Data plotting can be easily done in excel. Excel is a very easy and efficient tool for calculations and plotting of biological data and most people including me prefer it. With excel one has to plot the data and do all customization each and every time for a new data set. Therefore, when it comes to plotting multiple datasets of similar nature over and over again, using a programming language is more efficient. Once a template code for a plot is ready, one can plot any number of data sets with it in a few seconds. Here we will see how to plot a simple scatter plot by taking an example of growth profile (i.e. data of time vs O.D.) of a cell culture. The reading are from three experiments. The O.D.s were taken from 0 to 6 hours at an interval of one hour.

Python dictionary

Dictionaries are one of the built-in data types in Python. Like the language dictionary has words and their meaning written in it, the python dictionaries have 'key' and the 'value' corresponding to the 'key' stored in it. The python dictionary can be created by writing key-value pairs inside a curly bracket {}. An empty dictionary can be initiated as follows: d = {} Also, we can directly create a dictionary with initial key-value pairs. The key- value pairs must be in the format {key: value} . Following is an example. d = {'A': 3, 'Animals': ['dog', 'lion']} Here, we added two key-value pairs, {'A': 3} and { 'Animals': ['dog', 'lion']}. Note that the values can be a number, a string, a list or even a dictionary. They keys of the dictionary, however, should be an immutable objects such as strings, numbers, and tuples. Add new item to a dictionary New items in a dictionary can be added t...

Printing variables using f-strings in python

Image
Printing the values of variables is required. It may serve as an output for user to read or for the developers who are debugging their code. Sometimes we need the printed output to be easier to understand and not just a set of variable values . Using formatted string literals or f-strings is by far the most intuitive way to print out variables along with intermittent text. The simple example of printing using f-strings is as follows: a = 2 b = 3 print(f'The value of a is {a}, and the value of b is {b}.') The value of a is 2 and the value of b is 3.

What does the F-distribution in ANOVA mean?

Image
ANOVA (Analysis of variance) is an statistical methods used when we want to see if some treatment or strategy has produced any significant effect on the outcome or not. One-way ANOVA is used when only one factor is being tested. Two-way ANOVA is used when two factors are being tested at once. For the ANOVA, something called as a F-value is calculated by the following formula: F v a l u e = S S B S S W where, SSB = sum of squares between groups SSW = sum of squares within groups Also, based on the degrees of freedom within and between the groups, a F-critical value and a P-value is obtained. If the calculated F-value is greater than the F-critical value it is inferred that the treatment of strategy has statistically significant effect on the outcome. The P value is the probability of F-values to be greater than or equal to the calculated F-value if there was no effect o...

How to convert categorical text data into numerical data using OneHotEncoder

Image
 Machine learning algorithms handle numerical data better than text data. A dataset can contain categorical data in text form such a gender, food_type, taxonomic_class, etc. In order to better utilize the power of machine learning algorithms we would have to convert the categorical data in text form into numerical form. This can be done using encoders. There are a few types of encoders in scikit-learn that convert the categorical data into either binary or numerical data. Here we will learn about OneHotEncoder in scikit-learn. OneHotEncoder converts  the categorical data into binary data in which each category in  dataframe column is converted into one separate column where the value of the column is 1 in rows where that particular category is present. For example, if the category of gender in row number 12 in a dataset is 'male'. Then the column corresponding to 'male' category created by OneHotEncoder will have 1 in row number 12. We will see an example how to encod...

Reading and writing files using python

Image
Python can be used to open, read and write files. Let's take an example of a simple csv file. csv stands for comma separated values. csv files are basically text files with lines of text wherein each element in a line is separated by a comma. Below is an example of a csv file open in notepad.  

Iterating over lists in Python

Iterating over lists in Python The range(len()) method utilizes the range() and len() functions in python. The len() function gets the number of elements in the list and range() function generates a range of values that are same as the indices of the list elements. We can then iterate over the indices using a for loop. In [1]: # range(len()) # create lists a = [ 1 , 2 , 3 , 4 , 5 ] b = [ 4 , 2 , 7 , 1 , 9 ] c = [ 9 , 8 , 4 , 7 , 6 ] #create empty list to store results d = [] #loop for i in range ( len ( a )): d . append ( a [ i ] * b [ i ] * c [ i ]) print ( f ' { d =} ' ) d=[36, 32, 84, 28, 270] The zip() method utilizes the zip function. It basically createsa tuple from any iterables, in this example a list and returns the tuple.