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.
Use day_name() instead of dt.day_of_week in Pandas
More Relevant Posts
-
Dunder methods (aka “double underscore” or “magic methods”) are what make Python objects behave like built-ins. From __init__ for initialization to __str__ for readable output and __add__ for operator overloading — this is where OOP in Python gets powerful. Learn these, and your classes stop being basic… and start being Pythonic. #Python #PythonProgramming #DunderMethods #MagicMethods #OOP #LearnPython #CodingJourney #SoftwareDevelopment #PythonTips #DeveloperLife # AadyaTechnovate
To view or add a comment, sign in
-
Generate a #Python #Pandas DatetimeIndex of datetime values, specifying the frequency, by passing freq and a code: pd.date_range(start='2026-03-01', end='2026-05-01', freq='8h') This returns a 184-element DatetimeIndex with evenly-spaced datetime values in that period.
To view or add a comment, sign in
-
-
Have a #Python #Pandas series with datetime values, and want all those until now? Compare with pd.Timestamp.now(): df.loc[ pd.col('when') < pd.Timestamp.now() ] This returns the rows from df where the "when" column is before now.
To view or add a comment, sign in
-
-
Day 38/100 – #100DaysOfCode 🚀 Solved LeetCode #2011 – Final Value of Variable After Performing Operations (Python). Today I practiced string handling and simple iteration to compute the final value after a series of operations. Approach: 1) Initialize a variable x = 0. 2) Traverse through each operation in the list. 3) If the operation contains "++", increment x by 1. 4) Otherwise, decrement x by 1. 5) Return the final value of x. Time Complexity: O(n) Space Complexity: O(1) Simple logic but great practice for handling strings and loops 💪 #LeetCode #Python #DSA #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 20 | Problem-Solving Practice Today I worked on determining the number of days in a given month and year. • Implemented a basic conditional approach • Optimized the solution using a set and simplified leap year logic Focused on handling edge cases like invalid month inputs and leap years correctly. Consistency over intensity — showing up every day and improving step by step. GitHub: https://lnkd.in/g35tV9Gj #ProblemSolving #Python #LearningInPublic #Consistency
To view or add a comment, sign in
-
💡 Tiny Python tip that improves code clarity With a normal tuple, you have to remember what each index stands for. That knowledge lives in your head, not in the code. `namedtuple` fixes this by giving semantic meaning to each position. You still get immutability and performance, but with clear, self-documenting access. #Python #PythonProgramming #CleanCode #CodingBestPractices #CodeReadability
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
-
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