• Courses: LernerPython.com
• Newsletters: BetterDevelopersWeekly.com • BambooWeekly.com
• Books: PythonWorkout.com • PandasWorkout.com
• Videos: YouTube.com/reuvenlerner
Just about every day, my students ask great questions. I love sharing those questions (and my answers), along with other resources to help you improve your Python/Pandas fluency.
Improve your data skills with real data and current events! New questions every Wednesday. Solutions every Thursday.
x = 'this is a test'.split()
'*'.join(x)
':::'.join(x)
Not:
x.join('*')
Why not? The argument can be any string-returning iterable:
'*'.join('abcde')
'*'.join(str(x) for x in range(5))
'*'.join(open('filename.txt'))
x = 'this is a test'.split()
'*'.join(x)
':::'.join(x)
Not:
x.join('*')
Why not? The argument can be any string-returning iterable:
'*'.join('abcde')
'*'.join(str(x) for x in range(5))
'*'.join(open('filename.txt'))
df.select_dtypes(include='int64')
df.select_dtypes(include=['int64', 'float64'])
df.select_dtypes(exclude='int64')
df.select_dtypes(exclude='number') # all numbers
df.select_dtypes(include='str') # Pandas 3 str
df.select_dtypes(include='int64')
df.select_dtypes(include=['int64', 'float64'])
df.select_dtypes(exclude='int64')
df.select_dtypes(exclude='number') # all numbers
df.select_dtypes(include='str') # Pandas 3 str
if x == 10 and
y == 20:
print('Yes!') # ☹️
But with parentheses, Python sees it as one line:
if (x == 10 and
y == 20): # 🙂
print('Yes!')
Or in comprehensions…
[x*5
for x in range(10)
if x % 2]
if x == 10 and
y == 20:
print('Yes!') # ☹️
But with parentheses, Python sees it as one line:
if (x == 10 and
y == 20): # 🙂
print('Yes!')
Or in comprehensions…
[x*5
for x in range(10)
if x % 2]
# cell 1
df = [YOUR BIG DATAFRAME]
df # View it + stores in Out[1]
# cell 2
del(df) # df deleted, but Out[1] still has it!
Use df.head() instead of df to keep big values out of Jupyter's Out dict.
# cell 1
df = [YOUR BIG DATAFRAME]
df # View it + stores in Out[1]
# cell 2
del(df) # df deleted, but Out[1] still has it!
Use df.head() instead of df to keep big values out of Jupyter's Out dict.
We can prove it with the data — and using #Python #Pandas.
Challenge yourself with new, weekly real-world data problems: bambooweekly.com
We can prove it with the data — and using #Python #Pandas.
Challenge yourself with new, weekly real-world data problems: bambooweekly.com
letters = set('ygoanik') # From Mon, Jan 5
With sets, <= checks "subset or equal":
set('again') <= letters # True
set('garage') <= letters # False (r + e)
letters = set('ygoanik') # From Mon, Jan 5
With sets, <= checks "subset or equal":
set('again') <= letters # True
set('garage') <= letters # False (r + e)
How did it affect traffic? Are buses faster than before?
The latest Bamboo Weekly asks you to answer these questions (and more) with Pandas.
Level up your data-analysis skills at bambooweekly.com
How did it affect traffic? Are buses faster than before?
The latest Bamboo Weekly asks you to answer these questions (and more) with Pandas.
Level up your data-analysis skills at bambooweekly.com
d = dict.fromkeys('abc', 0)
But don't do this, since the value will be shared and mutable:
d = dict.fromkeys('abc', [])
d['a'].append('x')
d['b'].append('y')
print(d)
{'a': ['x', 'y'], 'b': ['x', 'y'], 'c': ['x', 'y']} 🤯
d = dict.fromkeys('abc', 0)
But don't do this, since the value will be shared and mutable:
d = dict.fromkeys('abc', [])
d['a'].append('x')
d['b'].append('y')
print(d)
{'a': ['x', 'y'], 'b': ['x', 'y'], 'c': ['x', 'y']} 🤯
round(1.3) # 1
round(1.6) # 2
round(1.61, 1) # 1.6
round(1.66, 1) # 1.7
Remember, .5 goes to the nearest *even* value:
round(1.5) # 2
round(2.5) # 2, yes 2! 🤯
round(3.5) # 4
round(1.65, 1) # 1.6
round(2.65, 1) # 2.6 🤯
round(3.65, 1) # 3.6
round(1.3) # 1
round(1.6) # 2
round(1.61, 1) # 1.6
round(1.66, 1) # 1.7
Remember, .5 goes to the nearest *even* value:
round(1.5) # 2
round(2.5) # 2, yes 2! 🤯
round(3.5) # 4
round(1.65, 1) # 1.6
round(2.65, 1) # 2.6 🤯
round(3.65, 1) # 3.6
s[::-1]
This works because:
- Empty start means "from the start"
- Empty end means "through the end"
- Step size of -1 means "go back 1 each time"
This returns a new value, from s's end to its start.
s[::-1]
This works because:
- Empty start means "from the start"
- Empty end means "through the end"
- Step size of -1 means "go back 1 each time"
This returns a new value, from s's end to its start.
s[i] # get 1 item
s[start:finish] # get slice
'a' in s # search
s.index('a') # where is a?
s.count('a') # how many as?
for item in s: # iterable
print(item)
s[i] # get 1 item
s[start:finish] # get slice
'a' in s # search
s.index('a') # where is a?
s.count('a') # how many as?
for item in s: # iterable
print(item)
Invoke weekday(). It returns an int; Mon is 0, Sat is 5 and Sun is 6. So:
today = datetime.datetime.now()
if today.weekday() > 4:
print('Weekend!')
else:
print('Not yet the weekend. :-(')"
Invoke weekday(). It returns an int; Mon is 0, Sat is 5 and Sun is 6. So:
today = datetime.datetime.now()
if today.weekday() > 4:
print('Weekend!')
else:
print('Not yet the weekend. :-(')"
>>> x = 100000
>>> y = 100000
>>> x is y
False
Surprised? That's because "is" is the wrong comparison:
• == asks: are these the same value?
• is asks: are these the same object?
You almost never care about question #2. And so, should rarely use "is".
>>> x = 100000
>>> y = 100000
>>> x is y
False
Surprised? That's because "is" is the wrong comparison:
• == asks: are these the same value?
• is asks: are these the same object?
You almost never care about question #2. And so, should rarely use "is".
In my latest video, I compare the spread of the flu in the US using both versions, comparing dtypes, memory usage, and query styles on real-life CDC data: youtu.be/1OqOM0FmFF0?...
In my latest video, I compare the spread of the flu in the US using both versions, comparing dtypes, memory usage, and query styles on real-life CDC data: youtu.be/1OqOM0FmFF0?...
• Does PyCon US affect PyPI downloads?
• Is uv gaining traction?
• How fast are people adopting Python 3.14?
Check it out: bambooweekly.com
• Does PyCon US affect PyPI downloads?
• Is uv gaining traction?
• How fast are people adopting Python 3.14?
Check it out: bambooweekly.com
In this video, I show you what has changed — but also where/why time zones can cause so many headaches, and what Pandas 3 changed.
Check it out: youtu.be/Zekos7T2KI4?...
In this video, I show you what has changed — but also where/why time zones can cause so many headaches, and what Pandas 3 changed.
Check it out: youtu.be/Zekos7T2KI4?...
My latest video explains how Pandas is standardizing warnings, to make it clearer, now and in the future: youtu.be/lwBCX2FuB-4?...
My latest video explains how Pandas is standardizing warnings, to make it clearer, now and in the future: youtu.be/lwBCX2FuB-4?...
Find out with my Pandas 3 playlist, youtu.be/TCSjgvtO714?....
New additions:
• Changes to sorted pd.concat and time series: youtu.be/2DVov1OfCFI?...
• Changed resample offsets: youtu.be/rZutMLQmWcY?...
Find out with my Pandas 3 playlist, youtu.be/TCSjgvtO714?....
New additions:
• Changes to sorted pd.concat and time series: youtu.be/2DVov1OfCFI?...
• Changed resample offsets: youtu.be/rZutMLQmWcY?...