Professional Documents
Culture Documents
Manipulating Dataframes - Beginner
Manipulating Dataframes - Beginner
• Numpy – arrays
F’string – It’s a way of getting dictionaries faster less verbose. Ex: k = “Allan” / f’{k} is a genius’
If it’s needed to use multiple quotes in the sentence, it should be considered to use different quote mark
for f string. Ex: f”{k} told ‘Fuck you’ to the teacher”.
Creating lists with for loop – Can be done by using the command append() or concat(), a for loop.
Arq = []
for i in range(2011,2021):
qgrid.show_grid(dataframe) – opens the dataframe for visualization with grids and filters.
Sorting items
df.sort_values(by=[‘Column_A’,‘Column_B’])
Filtering
Simple filtering
df = df[df['Column_A’] == 'filter'] – Will return a dataframe with data where there Will be the string
‘filter’ on ‘column A’
df1 = df["Column_A"].str.contains("Filter") – Will return a dataframe with Boolean check whether the
rows of ‘column A’ contains or not the string ‘Filter’
Data Analysis
Data Manipulation
replace() - it's not a string method. It is used to replace multiples elements in the dataframe. Ex:
titanic["Sex_short"] = titanic["Sex"].replace("Male": "M", "Female": "F") – It’ll create a column named
“Sex_Short”, copy the values from “Sex” and replace them with short for male and female.
Query – Allows one to search in the dataframe based on conditions. Ex: df.query( ‘a > b’)
The query sentence must be entered inside quote marks. For columns with spaces in the name it must
be entered with backtick ` ` . Ex: df.query( ‘ `Col Ex` == “Improving”’) . The strings must be entered with
doble quote marks.