🐍 Did you know that in Python, NaN is always a float. This has some interesting consequences when working with Series in Pandas: x = pd.Series([10, 20], index=["a","b"]) y = pd.Series([10, 30, 5], index=["a","b","c"]) print((x + y).dtype) # float64 Pandas aligns Series by index, so missing values like "c" in x are treated as NaN, which can only be a float, causing all numbers in the result to be upcast to float64. #Python #Pandas #PythonTips #Coding
Python Pandas Series Alignment and NaN Values
More Relevant Posts
-
What Really Happens When You Pass a Variable to a Function in Python? In Python, variables don’t hold values — they hold references to objects. When you pass a variable to a function: 👉 Python passes the reference, not a copy of the object. This model is often called “pass-by-object-reference” (or call by sharing). Why this confuses people? Immutable objects (int, str, tuple): Reassignment inside a function creates a new object → original stays unchanged. Mutable objects (list, dict, set): In-place modification changes the same object → caller sees the change. So it feels like: Immutable → pass by value Mutable → pass by reference But that’s just an illusion. The real rule Python always passes a reference to an object. What you do with that reference determines the outcome. #Python #ProgrammingConcepts #PythonInternals #Mutable #Immutable #CleanCode
To view or add a comment, sign in
-
Most Python code runs on one core — even if your machine has 8, 12, or 16. That’s fine… until your script starts taking forever 😪 ✨Multiprocessing✨ can change that! But here’s the catch: it's often misunderstood, misused, or missed entirely. This post isn’t just “how it works.” It’s about when it actually helps, what to avoid, and how it compares to the other options — threading and asyncio. You’ll leave knowing when not to reach for multiprocessing — which is just as important. 📎 Link in comments to get the full breakdown! (with code examples and real use cases) #Python #SoftwareEngineering #CodePerformance #DataEngineering #PythonTips #ScalableCode #BackendDevelopment #HighPerformanceComputing #AsyncProgramming #DeveloperInsights #StrataScratch
To view or add a comment, sign in
-
Today I learned about Tuples in Python — completely new for me. • Tuples are ordered, so indexing works • They allow duplicate values • They are immutable — once created, they can’t be changed • This immutability makes them useful for fixed & safe data • Discovered simple but powerful methods like .count( ) and .index( ) One step at a time. 💻🐍 Which Python topic felt confusing at first but later clicked for you? #python #learninginpublic #codingjourney #pythonbeginner #
To view or add a comment, sign in
-
🚀Discovered why Python lists kill performance (200ms vs 2ms for 1M elements!) while NumPy delivers 100x speedup + 8x less memory. Explained with a chef analogy: cache misses = running to the store, GIL = one chef rule. Read full blog on medium: https://lnkd.in/dWDGWtuw #NumPy #Python #DataScience #Performance #GenAi #DataScience
To view or add a comment, sign in
-
-
Can 40 lines of Python grow a forest? 🌳 I’ve been exploring recursive logic and randomization to create these "Live Trees" using Python's Turtle module. No two runs are ever the same. By using random.uniform for branch length and random.randint for angles, the code mimics the organic unpredictability of nature. find the code at https://lnkd.in/dkWXd6B8 Tech stack: 🐍 Python 🔢 NumPy 🎨 Turtle Graphics It’s amazing how simple math can create such complex, organic beauty. #Python #CreativeCoding #Fractals #GenerativeArt #Python
To view or add a comment, sign in
-
One Python line that quietly hurts performance: 🪫👀 “if x in my_list:” It looks innocent and works perfectly—until my_list grows. Why it matters: • Set lookup → O(1) • List lookup → O(n) Many performance problems don’t start with bad code, but with “It works, so it’s fine.” In Python, choosing the right data structure is a design decision, not an implementation detail. #Python #Performance #SoftwareEngineering #CleanCode
To view or add a comment, sign in
-
How Python Manages Memory: Mutable vs Immutable One concept that silently affects performance, bugs, and behavior in Python is mutability. Immutable objects 👉 int, float, str, tuple Their value cannot be changed in place Any “modification” creates a new object in memory Safer, predictable, hashable (used as dict keys) Mutable objects 👉 list, dict, set Can be modified without changing memory reference Faster updates, but risk of unexpected side effects Changes reflect across all references Why this matters in real projects - Unexpected bugs when modifying lists passed to functions - Memory inefficiency when repeatedly modifying strings - Confusing behavior in function arguments & shared data #Python #MemoryManagement #Mutable #Immutable #PythonInternals #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Writing to a File (Python) Writing to a file in Python involves using the 'w' or 'a' modes. The 'w' mode overwrites the file if it exists, while the 'a' mode appends to the end of the file. The `write()` method writes a string to the file. It's important to handle potential exceptions, such as `IOError`, when writing to a file. Remember to explicitly close the file or use the `with` statement to ensure changes are saved and resources are released. Learn more on our app: https://lnkd.in/gefySfsc #Python #PythonDev #DataScience #WebDev #professional #career #development
To view or add a comment, sign in
-
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