Introduction
Installing the necessary software
Interacting with data in external sources
1. How to effectively read an xlsx file
Skip reading rows when reading a dataframe
How to read a specific sheet from an excel file
Set the index of a dataframe upon reading it
Read specific columns from an excel file
Read data from World Bank
Send many dataframes into the same Excel file
Send a dataframe to a CSV
Hide Warnings
Reading rows from top/bottom (nrows, skipfooter)
Check if an Excel cell is empty
Check the version of the installed packages
Hide special warnings
Index of a dataframe
1. Set and reset the index
Change the name of the index of a dataframe
Find the row/column index of any element of a dataframe
The enumerate() command to enumerate rows/elements
Sort the index of a dataframe sort_index
Lists
How to sort the elements of a list
Remove elements from a list
Create a sublist from another list
List comprehension from consecutive numbers
Print first / last elements of a list
Place in a list the elements of another list
Remove all occurrences of an element
pop() versus remove()
List comprehensions
Slicing
Enumerate, index
series.isin(list)
Count how many times an element is in a list
Make a copy and an alias of a list
Important Dataframe operations
Return elements from a dataframe
Delete rows / columns (iloc, drop)
Read indices and values of a dataframe
Show the max number of rows/columns
Create a copy of a dataframe
Take a backup of a dataframe (copy versus =)
Change specific values in a dataframe
Make a new column and fill it with the values of another column
Change the order of columns in a dataframe
New row and fill it with the values of other rows
New column with values 1,2,3… (arange)
pivot tables
Rename rows / columns of a dataframe
Use a dictionary to create a dataframe
Transpose of a dataframe
Select rows/columns of a dataframe
Repeat a row/column (np.repeat)
Sorting the columns
Change the datatype of a row/column (astype)
Select specific rows/columns (loc, arange)
How to delete many rows from a dataframe
Get the value under another column of the same row
Use iteritems on a dataframe
Sort the values of a column (sort_values)
Populate a column via list, array, series
Define a dataframe with / without a dictionary
Define a dataframe using list comprehension
The Apply command
Format the values of a dataframe to percentages
Format the elements of a dataframe to 1 decimal point
Apply a function to the elements of a series / dataframe
Loops
Prevent data transfer from dataframe to dictionary
Prevent duplicate values in a dataframe
Prevent duplicate values while using True, Break
Break, continue, pass
For, else
While, For equivalence
While True
While , Else
Multilevel (columns) dataframes
How to define it
How to rename a column
How to remove a level
Print levels in a single cell (merge_cells)
From merged (dataframe) to unmerged (excel)
How to implement iteritems
Conditionals
If, elif
inline if statement
Print statement with if-else embedded
Logicals
AND, OR, FALSE, TRUE
NOT
The De Morgan Laws
Comparison of : int, str, Float, Bool
Type conversions: int , float, str, bool
Combining NOT with empty string / lists
The meaning of : x = None, [] , ” “
Difference between ‘is’ and ‘=’
Tuples
Iterate via for-loop
Join two tuples
Define a tuple
Sort a tuple
Enumerate a tuple (enumerate, index)
Find the frequency of elements (count)
Tuple immutability
NaN values
Remove NaN values by deleting rows/columns
How to find if a dataframe has NaN values
Use min_count to sum in presence of NaN values
Place NaN values in a dataframe , manually
Sum rows by ignoring NaN (skipna)
Replace missing values with 0
Python Implementation of Excel functions
Modelling VLOOKUP in Python
Modelling SUMIFS in Python
Modelling AVERAGEIFS in Python
Strings
Evaluate String expressions using eval()
Remove trailing characters using rstrip, lstrip
Break a string in sets using wrap
Select part of a string
Remove white space using replace ()
Search for multiple occurrences of a subtext
Select specific characters from a column using “str”
Replace a character or a word from inside a string
Unite strings from inside a list using “join”
Multiline strings ” ” “
Formating strings and f-strings (format)
Count how many times a character is inside a string
in, find() with strings
right-justify text using rjust
Creating variables
Using the function globals()
Multiple assignment
Use “global” to change variables
Sets
Define a set, add/remove elements
Convert a list/string to a set
Difference of two sets: symmetric difference
Set comprehension
Subset, superset, proper subset/superset
Intersection and union
Series
Edit strings inside series using. .str[]
Create a series object of a constant value
Select a column as Series versus as a Dataframe
Broadcasting (saving) an array to a Series
Numpy arrays
Concatenate two arrays
linspace (equally spaced numbers)
Reshaping the array
1D, 2D, 3D arrays from lists
Modify elements of an array
Use arange to make 1D and 2D arrays
eye, ones, zeros
flattening an array
Functions
Docstring
Count how many times a function is called
How to return many values from a function
Default values for parameters
A function calling another function
Date objects
Update a DateTimeIndex
The Workalendar package for Country dates
Timedelta() for time conversions
Datatypes
Use __name__
Check if the datatype is int/ float/ str/ NaN/ None
dtypes, astype() and the type of the dataframe elements
Converting elements of a column via astype
Dictionaries
Define and loop through a dictionary
Find the number of elements in a dictionary
Convert to a list/set of keys/values
Convert a dataframe to a dictionary
Print the first 6 elements of a dictionary
What it means : for x in dictionary
Convert a single value into a dictionary (keys)
Avoid errors when a key is not found (get)
Join two dictionaries (**)
Dictionary comprehension
Delete a key from a dictionary
Sort a dictionary
Mutability of a dictionary
Special dictionaries
Default dictionaries
Maths
Trigonometry, infinity, pi
regular division, integer division, modulo division, //, %
dot product of 2 arrays
Errors
Try Except block
the “finally” statement
Raise errors based on user input
How to raise own errors
The Random package
random choice
randint
randrange
random.random, random.seed
random.sample (sample without replacement)
Fix the random seeds using a function