Elektrine
Log in Register
Paige Chat Timeline Gallery Friends Email Drive DNS Private DNS Domains VPN Kairo Nerve
Remote

Reuven M. Lerner

@Reuven@fosstodon.org
mastodon 4.7.3
  • Open on fosstodon.org

Helping you become fluent with Python and Pandas since 1995.

0 Followers
0 Following
20 Posts
Joined November 05, 2022
Python courses, excercises, and mentoring:
http://LernerPython.com
Pandas challenges:
https://BambooWeekly.com
Python articles:
https://BetterDevelopersWeekly.com
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Reading a CSV into #Python #Pandas, and parse_dates doesn't recognize the format? Pass the date_format keyword arg:

df = pd.read_csv(filename,
parse_dates=['x', 'y'],
date_format='%Y-%m-%d %H:%M:%S')

All strftime codes work!

fosstodon.org

Fosstodon

3
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Having a tough time remembering #Python strptime vs. strftime?

- The "p" (strptime) is for parsing, getting a datetime from a string
- The "f" (strftime) is for formatting, getting a string from a datetime

For help remembering the format codes, turn to https://www.strfti.me/ !

fosstodon.org

Fosstodon

3
0
2
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

If a #Python string contains an ISO-formatted date, skip strptime and use datetime.fromisoformat:

import datetime as dt
dt.datetime.fromisoformat('2026-04-12') # returns datetime at midnight
dt.datetime.fromisoformat('2026-04-12 12:34:56') # returns datetime at 12:34:56

fosstodon.org

Fosstodon

2
0
2
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 6mo ago

Do you love analyzing data with #Python and #Pandas?

And have you been following NASA's Artemis II mission?

Then you'll really enjoy tomorrow's Bamboo Weekly!

More info: https://BambooWeekly.com

fosstodon.org

Fosstodon

2
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago
Replying to
@rye than guessing! Sorry... I wrote these in a series of small posts and forgot they wouldn't be seen that way! Slower than getting the day number with dt.dayofweek.
1
0
0
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Do Americans pay more taxes than in other countries? Do they pay more in income taxes?

Explore OECD data with #Python, #Pandas, Marimo, and Claude Code (plus the new marimo-pair skill) in the latest Bamboo Weekly, and find out!

Read all about it: https://BambooWeekly.com

fosstodon.org

Fosstodon

1
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

It's tax day in the US — and according to Gallup, Americans think taxes are too high. But... how high are they vs. other countries?

In the latest Bamboo Weekly, I pose 6 questions about taxes. Can you solve them with marimo-pair, Marimo, Claude Code, and #Python #Pandas?

Check it out: https://BambooWeekly.com

fosstodon.org

Fosstodon

1
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Reading a CSV into #Python #Pandas, and want a column to be treated as datetime values? Use parse_dates:

df = pd.read_csv(filename,
parse_dates=['x', 'y'])

Bonus: The PyArrow engine often (not always) parses columns that look like dates.

fosstodon.org

Fosstodon

1
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Want to take a #Python #Pandas series of strings, and get datetime values? Use pd.to_datetime:

pd.to_datetime(df['x'])

Notice: It's not a method! It's a top-level pd function.

Specify a non-standard "format" with a strftime string:

pd.to_datetime(df['x'], format='%d/%m/%Y')

fosstodon.org

Fosstodon

1
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 6mo ago

Want to parse a #Python string into a datetime? Use strptime, passing (a) the string and (b) the date format spec:

datetime.datetime.strptime('2026-04-01', '%Y-%m-%d')
datetime.datetime.strptime('26-April-01', '%y-%B-%d')

Both return datetime.datetime(2026, 4, 1, 0, 0)

fosstodon.org

Fosstodon

1
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 6mo ago

Want to format a #Python datetime as a string? Use strftime:

dt = datetime.datetime(2026, 4, 1, 13, 15, 17)

dt.strftime('%Y-%m-%d') # '2026-04-01'
dt.strftime('%Y-%m-%d %H:%M:%S') # '2026-04-01 13:15:17'
dt.strftime('%y-%B-%e %H:%M:%S') # '26-April- 1 13:15:17'

fosstodon.org

Fosstodon

1
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 6mo ago

Want a #Python datetime with a timezone? Use the "zoneinfo" module:

import zoneinfo
tz = zoneinfo.ZoneInfo('US/Eastern')

Then pass it to the "tzinfo" keyword arg:

dt = datetime.datetime(2026, 4, 1, 13, tzinfo=tz)

fosstodon.org

Fosstodon

1
0
2
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 6mo ago

The Strait of Hormuz is closed — which, we know, is stopping oil exports.

But a lot of the world's fertilizer also comes from there.

How much? And which countries depend on it?

That's what we analyze, with #Python #Pandas, in the latest Bamboo Weekly!

Check it out: https://BambooWeekly.com

fosstodon.org

Fosstodon

1
0
2
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago
Replying to
Info session: https://us02web.zoom.us/webinar/register/WN_wXq9Sn1uRrOfzPzMRcSL6w Or learn more at: https://lernerpython.com/code-with-claude/
us02web.zoom.us
0
0
0
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Want to know if values in a #Python #Pandas datetime series are at the start/end of a period? Get a boolean series from:

df['x'].dt.is_month_start # or dt.is_month_end
df['x'].dt.is_quarter_start # or dt.is_quarter_end
df['x'].dt.is_year_start # or dt.is_year_end

fosstodon.org

Fosstodon

0
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Use dt.day_of_week to get the day number from a #Python #Pandas datetime series.

But is 0 Sunday or Monday? Or not used at all?

Better: Use the day_name method:

df['x'].dt.day_name()

Good news: It returns a series of strings!
Bad news: It's 4x slower.

fosstodon.org

Fosstodon

0
1
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 5mo ago

Want to grab a part of datetime value in a #Python #Pandas data frame column? Use "dt":

df['x'].dt.year
df['x'].dt.hour
df['x'].dt.minute
df['x'].dt.day_of_week # or dayofweek or weekday

day_of_week returns an integer, where 0 is Monday and 6 is Sunday.

fosstodon.org

Fosstodon

0
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 6mo ago

Artemis II is nearly over — but there's still time to solve six data-analysis problems about Orion's location and speed with #Python and #Pandas!

New data challenges every Wednesday. Solutions every Thursday.

Learn more: https://BambooWeekly.com

fosstodon.org

Fosstodon

0
0
1
0
Open post
Reuven M. Lerner @Reuven@fosstodon.org
· 6mo ago

Want a #Python datetime? Just invoke datetime.datetime:

dt = datetime.datetime(2026, 4, 1, 13, 18, 20)
str(dt) # '2026-04-01 13:18:20'

Omitted time units are 0:

dt = datetime.datetime(2026, 4, 1, 13)
str(dt) # '2026-04-01 13:00:00'

fosstodon.org

Fosstodon

0
0
1
0
Back
313k7r1n3
Elektrine

Tor hidden service

elekhj7afj4qnrr4yd3bkzslsyo5jgfxw3orgjkhlcxifueodybyiiad.onion

I2P eepsite

j6b6cyk6gjmepjih7jjadxgxvvf3lzzujljuu2v4biemzpg3naya.b32.i2p

Platform

  • Email
  • Chat
  • Timeline
  • VPN
  • DNS

Company

  • About
  • Contact
  • FAQ
  • Lite (no JS)

Legal

  • Terms of Service
  • Privacy Policy
  • Transparency Report
  • Report Abuse
  • Warrant Canary
  • VPN Policy

Support

  • support@elektrine.com
  • Report Security Issue
Mail client setup IMAP mail.elektrine.com:993 POP3 mail.elektrine.com:995 SMTP mail.elektrine.com:465
© 2026 Elektrine. All rights reserved. Server: 03:16:42 UTC