Uploaded December 2019 | Updated November 2026, 1 hour ago
The stringr library is part of the R tidyverse and provides a range of convenience functions for working with character strings. In this first lesson of the stringr series, we look at several basic string manipulation functions.
stringr Series Code Notebook:
kaggle.com/hamelg/stringr-tutorials
stringr overview:
stringr.tidyverse.org
stringr cheatsheet:
github.com/rstudio/cheatsheets/blob/master/strings.pdf
Follow DataDaft on social media for news and updates:
Twitter: twitter.com/DataDaft
Join the DataDaft Discord to discuss all things data science:
discord.gg/ZS2yPNw
#tidyverse #rprogramming #datascience
The stringr library is part of the R tidyverse and provides a range of convenience functions for working with character strings. In this first lesson of the stringr series, we look at several basic string manipulation functions.
stringr Series Code Notebook:
kaggle.com/hamelg/stringr-tutorials
stringr overview:
stringr.tidyverse.org
stringr cheatsheet:
github.com/rstudio/cheatsheets/blob/master/strings.pdf
Follow DataDaft on social media for news and updates:
Twitter: twitter.com/DataDaft
Join the DataDaft Discord to discuss all things data science:
discord.gg/ZS2yPNw
#tidyverse #rprogramming #datascience
![How To Flatten Nested Lists in Python
↓ Code Available Below! ↓
This video shows how to flatten nested lists in Python.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
nested = [[1,2,3],[4,5,6],[7,8,9]]
# Depth 2 flatten with list comprehension
flattened = [num for sublist in nested for num in sublist]
print(flattened)
# Depth 2 flatten with for loops
flattened2 = []
for sublist in nested:
for num in sublist:
flattened2.append(num)
print(flattened2)
# Flatten with numpy
import numpy as np
np.array(nested).flatten()
# Nested lists greater than depth 2
nested3 = [nested, nested]
# Flatten depth 3 nested with numpy
import numpy as np
np.array(nested3).flatten()
# Add extra sublists as extra loops:
[num for sub1 in nested3 for sub2 in sub1 for num in sub2]
# Flatten lists with unequal levels of nesting
unequal_nest = [1 , [2, 3], [[4,5],[6, 7]]]
def flatten_list(x):
for item in x:
if type(item) in [list]:
for num in flatten_list(item):
yield(num)
else:
yield(item)
list(flatten_list(unequal_nest))
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only How To Flatten Nested Lists in Python](https://i.ytimg.com/vi/p9Cp5w2HV7g/mqdefault.jpg)

![How to Check the First and Last Rows of a Data Frame in Pandas (Python)
↓ Code Available Below! ↓
This video shows how to check the first and last rows of pandas data frame using the both the built in head and tail functions as well as index slicing with iloc. Checking the head and tail of a data frame is a common operation to get a sense of what your data looks like and avoid printing too many rows to the console. It is also a quick way of getting the top n results from a sorted data frame.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import pandas as pd
import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset(mtcars, datasets, cache=True).data
# Check the first n rows with df.head(n)
# Equivalent to df.iloc[0:n]
mtcars.head(6)
# Check the last n rows with df.tail(n)
# Equivalent to df.iloc[len(df)-n:len(df)]
mtcars.tail(6)
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only How to Check the First and Last Rows of a Data Frame in Pandas (Python)](https://i.ytimg.com/vi/r5JcWGIfgBg/mqdefault.jpg)






![How To Use apply() In Pandas (Python)
↓ Code Available Below! ↓
This video shows how to apply functions to columns and rows pandas data frames using .apply(). The .apply() function operates on pandas series or data frames and applies a function to each element of a single series (such as each record in a column of a data frame) or to each row or column of a data frame. .apply() can be a useful way to generate aggregate statistics for each column or to generate new columns.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import pandas as pd
data = pd.DataFrame({power_level: [12000, 16000, 4000, 1500, 3000,
2000, 1600, 2000, 300],
uniform color: [orange, blue, black, orange,
purple, green, orange, orange,orange],
species: [saiyan,saiyan,saiyan,half saiyan,
namak,human,human,human,human]},
index = [Goku,Vegeta, Nappa,Gohan,
Piccolo,Tien,Yamcha, Krillin,Roshi])
data
# Use .apply() to apply a function to a Series (single column)
def my_function(x, h, l):
if x > h:
return(high)
if x > l:
return(med)
return (low)
data[power_level].apply(my_function, args = [10000, 2000])
# Apply a function to each column with axis = 0
# Can be used to create new rows/summary rows
def mode(x):
return x.mode()
data.apply(mode, axis = 0)
# Apply a function to each row with axis = 1
# Can be used to create new columns/summary columns
def max_str_len(x):
return max([len(str(v)) for v in x])
data.apply(max_str_len, axis = 1)
# Apply a function to each row, referencing column names:
def make_char_string(x):
return(f{x.species} with power level: {x.power_level})
data.apply(make_char_string, axis = 1 )
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only How To Use apply() In Pandas (Python)](https://i.ytimg.com/vi/smPLY_5gVv4/mqdefault.jpg)
