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.
Reuven Lerner’s Post
More Relevant Posts
-
Here’s a tiny Python change that pays off fast. Python tip: use `@dataclass(slots=True)` for high-volume models. It removes per-instance `__dict__`, which usually means lower memory usage and slightly faster attribute access. Great for DTOs, parser outputs, event payloads, and cache objects where shape is fixed. Mini rule: if the object schema is stable, add `slots=True` by default. #Python #Performance #CodeQuality #SoftwareEngineering
To view or add a comment, sign in
-
-
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')
To view or add a comment, sign in
-
-
Want to find which time period contains a #Python #Pandas datetime? Use to_period: pd.Timestamp.now().to_period('1D') pd.Timestamp.now().to_period('6W') This returns a Pandas "Period" object, useful (among other things) for checking if two dates are within the same period.
To view or add a comment, sign in
-
-
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://buff.ly/oEdYGMI !
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development