Filtering a dataframe can be achieved in multiple ways using pandas. There are times when you simply need to update a column based on a condition which is true or vice-versa. In pandas dataframe there are some inbuilt methods to achieve the same using .where() and .mask().
Initiating a dummy dataframe with some columns to understand the same -
import pandas as pd
import numpy as np
dummy_data = pd.DataFrame(
np.array([[1, 2, 3], [4, 5, np.nan], [7, 8, 9], [3, 2, np.nan], [5, 6, np.nan]]),
columns=['Column 1', 'Column 2', 'Column 3'])
dummy_data
Column 1 | Column 2 | Column 3 | |
---|---|---|---|
0 | 1.0 | 2.0 | 3.0 |
1 | 4.0 | 5.0 | NaN |
2 | 7.0 | 8.0 | 9.0 |
3 | 3.0 | 2.0 | NaN |
4 | 5.0 | 6.0 | NaN |
String operations in python, sometimes can be a bit tedious, specially when we need to pass variables within Strings.
Although there are multiple ways to achieve the same, but some of the them are
Declaring some variables -
Name = 'Python'
Framework = 'Django'
"Language - {0}, Framework - {1}".format(Name, Framework)
‘Language - Python, Framework - Django’
f"Language - {Name}, Framework - {Framework}"
‘Language - Python, Framework - Django’
Working with multiple data frames often involves joining two or more tables to in bring out more no. of columns from another table by joining on some sort of relationship which exists within a table or appending two tables which is adding one or more table over another table with keeping the same order of columns.
Example of append data -> monthly files of revenue sheets of a company and wee need at end of the year to be clubbed into single table.