✅ *Python Basics: Part-1* *Data Types & Variables* 🐍📚 🎯 *What is a Variable?* A *variable* stores data in memory to be used and modified later. Example: ```python name = "Alice" age = 25 ``` 🔹 *Common Python Data Types:* ● *String (`str`)* – Text data ```python message = "Hello, World" ``` ● *Integer (`int`)* – Whole numbers ```python count = 42 ``` ● *Float (`float`)* – Decimal numbers ```python price = 19.99 ``` ● *Boolean (`bool`)* – True or False ```python is_valid = True ``` ● *List (`list`)* – Ordered, mutable sequence ```python fruits = ["apple", "banana", "cherry"] ``` ● *Tuple (`tuple`)* – Ordered, *immutable* sequence ```python coords = (10.5, 20.7) ``` ● *Set (`set`)* – Unordered collection of unique elements ```python colors = {"red", "green", "blue"} ``` ● *Dictionary (`dict`)* – Key-value pairs ```python person = {"name": "Alice", "age": 25} ``` 🔑 *Dynamic Typing:* Python automatically detects the type, so you don’t need to declare it. 💬 *Double Tap ❤️ for Part-2!*
Python Basics: Data Types & Variables
More Relevant Posts
-
✅ *10 Python Snippets Every Data Analyst Should Know* 📊🐍 ➊ *Read CSV File* ```python import pandas as pd df = pd.read_csv("data.csv") ``` ➋ *Check for Missing Values* ```python df.isnull().sum() ``` ➌ *Drop Duplicate Rows* ```python df = df.drop_duplicates() ``` ➍ *Filter Rows by Condition* ```python filtered = df[df["Age"] > 30] ``` ➎ *Group By & Aggregate* ```python df.groupby("Department")["Salary"].mean() ``` ➏ *Rename Columns* ```python df.rename(columns={"old_name": "new_name"}, inplace=True) ``` ➐ *Sort Data* ```python df.sort_values(by="Salary", ascending=False) ``` ➑ *Find Correlation* ```python df.corr() ``` ➒ *Convert Data Type* ```python df["Date"] = pd.to_datetime(df["Date"]) ``` ➓ *Describe Summary* ```python df.describe()
To view or add a comment, sign in
-
🧠 Python Concept: setdefault() in dictionary Add default values smartly 😎 ❌ Traditional Way data = {} key = "fruits" if key not in data: data[key] = [] data[key].append("apple") print(data) ❌ Problem 👉 Extra condition 👉 More lines ✅ Pythonic Way data = {} data.setdefault("fruits", []).append("apple") print(data) 🧒 Simple Explanation Think of setdefault() like a smart helper 🤖 ➡️ If key exists → use it ➡️ If not → create with default value 💡 Why This Matters ✔ Cleaner code ✔ Avoid key checking ✔ Useful in grouping data ✔ Common in real-world apps ⚡ Bonus Example data = {} items = [("fruit", "apple"), ("fruit", "banana")] for key, value in items: data.setdefault(key, []).append(value) print(data) 👉 Output: {'fruit': ['apple', 'banana']} 🐍 Don’t check keys manually 🐍 Let Python handle it smartly #Python #PythonTips #CleanCode #LearnPython #Programming #DeveloperLife #100DaysOfCode
To view or add a comment, sign in
-
-
✅ *10 Python Snippets Every Data Analyst Should Know* 📊🐍 ➊ *Read CSV File* ```python import pandas as pd df = pd.read_csv("data.csv") ``` ➋ *Check for Missing Values* ```python df.isnull().sum() ``` ➌ *Drop Duplicate Rows* ```python df = df.drop_duplicates() ``` ➍ *Filter Rows by Condition* ```python filtered = df[df["Age"] > 30] ``` ➎ *Group By & Aggregate* ```python df.groupby("Department")["Salary"].mean() ``` ➏ *Rename Columns* ```python df.rename(columns={"old_name": "new_name"}, inplace=True) ``` ➐ *Sort Data* ```python df.sort_values(by="Salary", ascending=False) ``` ➑ *Find Correlation* ```python df.corr() ``` ➒ *Convert Data Type* ```python df["Date"] = pd.to_datetime(df["Date"]) ``` ➓ *Describe Summary* ```python df.describe() ``` 💬 *Tap ❤️ for more!*
To view or add a comment, sign in
-
✅ *10 Python Snippets Every Data Analyst Should Know* 📊🐍 ➊ *Read CSV File* ```python import pandas as pd df = pd.read_csv("data.csv") ``` ➋ *Check for Missing Values* ```python df.isnull().sum() ``` ➌ *Drop Duplicate Rows* ```python df = df.drop_duplicates() ``` ➍ *Filter Rows by Condition* ```python filtered = df[df["Age"] > 30] ``` ➎ *Group By & Aggregate* ```python df.groupby("Department")["Salary"].mean() ``` ➏ *Rename Columns* ```python df.rename(columns={"old_name": "new_name"}, inplace=True) ``` ➐ *Sort Data* ```python df.sort_values(by="Salary", ascending=False) ``` ➑ *Find Correlation* ```python df.corr() ``` ➒ *Convert Data Type* ```python df["Date"] = pd.to_datetime(df["Date"]) ``` ➓ *Describe Summary* ```python df.describe() ``` 💬 *Tap ❤️ for more!*
To view or add a comment, sign in
-
🧠 Python Concept: itertools.groupby() Grouping data like a pro 😎 ❌ Manual Grouping data = ["a", "a", "b", "b", "c"] result = {} for item in data: if item not in result: result[item] = [] result[item].append(item) print(result) 👉 More code 👉 Manual handling ✅ Pythonic Way (groupby) from itertools import groupby data = ["a", "a", "b", "b", "c"] groups = {k: list(v) for k, v in groupby(data)} print(groups) ⚠️ Important Gotcha data = ["b", "a", "b", "a"] groups = {k: list(v) for k, v in groupby(data)} 👉 Output will be WRONG 😳 👉 Because groupby() needs sorted data ✅ Correct Way from itertools import groupby data = ["b", "a", "b", "a"] data.sort() groups = {k: list(v) for k, v in groupby(data)} 🧒 Simple Explanation 👉 groupby() groups consecutive items 👉 Not all same items automatically 💡 Why This Matters ✔ Cleaner grouping ✔ Faster processing ✔ Useful in data pipelines ✔ Important in interviews ⚡ Real-World Use ✨ Log processing ✨ Data aggregation ✨ Report generation 🐍 Group smart, not manually 🐍 Know the hidden behavior #Python #AdvancedPython #CleanCode #DataProcessing #SoftwareEngineering #Programming #DeveloperLife
To view or add a comment, sign in
-
-
If you can use Excel, you can use SQL. If you can use SQL, you can use Python. ↳ Therefore, if you can use Excel, you can use Python. In mathematics, this is called the transitive property. You’re chaining skills together through a shared foundation and building off each one. There are people still fighting over Excel vs SQL vs Python. They literally do the EXACT same things, they just do it at different scales. Here’s how you can leverage each one: ↳ Excel to quickly explore & validate ↳ SQL to extract & aggregate from databases ↳ Python to clean, transform, and automate If you know the logic in Excel, you already know how to do it everywhere else. Here's your translation guide: Filter rows: ↳ Excel: Data > Filter ↳ SQL: WHERE ↳ Python: df[df[ ’column’ ] == ‘value’ ] Combine Data from Two Sheets/Tables: ↳ Excel: XLOOKUP() ↳ SQL: JOIN ↳ Python: pd.merge() Summarize Data by Category: ↳ Excel: Pivot Tables ↳ SQL: GROUP BY ↳ Python: df.groupby() Conditional Column Logic: ↳ Excel: IF() ↳ SQL: DISTINCT ↳ Python: np.where() Remove Duplicates: ↳ Excel: Remove Duplicates ↳ SQL: DISTINCT ↳ Python: df.drop_duplicates() Sort Data: ↳ Excel: Data > Sort ↳ SQL: ORDER BY ↳ Python: df.sort_values() Each tool has a job. You HAVE to know when to use which, and your life will get way easier. ♻️ repost for your network and 🔖 save this for later
To view or add a comment, sign in
-
-
I once spent 3 hours writing a SQL query. Nested subqueries. 6 CTEs. CASE WHEN inside CASE WHEN. It was a mess. And I knew it. Because in the back of my mind I kept thinking: "This would be 4 lines of Python." SQL is brilliant at set-based thinking: • Filter millions of rows instantly • Join tables, aggregate, rank • Feed a dashboard that 50 people use But the moment your logic becomes procedural row by row, step by step, loop by loop SQL starts fighting you. That's Python's territory: • Custom row-by-row logic • Messy data cleaning • Statistics, forecasting, and machine learning • Automation and APIs • Anything SQL does in 40 lines that Python does in 4 The best analysts don't pick a side. They recognize the moment SQL is working against them. And they switch. The skill isn't SQL. The skill isn't Python. The skill is knowing when to switch.
To view or add a comment, sign in
-
-
🕶️ Do you want to know what Python really is? (Or how to find the exit from the Excel Matrix) Remember that scene where Morpheus offers Neo a choice? 🔵🔴 In logistics and supply chain planning, most of us choose the blue pill every single day: You copy the same data over and over. You build a VLOOKUP that crashes because you’ve hit 50,000 rows. You keep believing that "this is just how it has to be." But if you’re reading this, it means you’re looking for the red pill. You want to see how deep the automation rabbit hole goes. 🐇 💊 Where to find the code (and avoid becoming Agent Smith) People fear that the Matrix (read: Python) requires memorizing thousands of commands. Nonsense! Even "The One" didn’t know everything at once—he simply "downloaded" the programs he needed into his head. 💿 Here are your data-loading ports: 1. Libraries (The Kung-Fu Programs): You don't spend 20 years learning to fight. You type import pandas as pd and suddenly: "I know Kung-Fu" (translation: your data sorts, merges, and cleans itself). Libraries are pre-built move sets that someone else has already mastered for you. 2. Stack Overflow (The Oracle): If your code throws an error, don't panic. You type that error into Google and visit the Oracle. You’ll always find someone who already fixed it years ago. Copying code isn't a glitch in the Matrix—it’s the fastest way to the goal! 3. Documentation (The Source Code): This is the manual for the world. You don’t read it like a novel. You dip in only when you need to know how to "bend the spoon" (or how to reformat dates across 100 files at once). ✨ Your mission for today: Stop trying to jump across skyscrapers in one leap. Find one small, boring task that eats up 15 minutes of your day. Search for a Python "spell" to fix it. Remember: The system relies on your sacrificed time. Python lets you take that time back. The question is: Which pill are you taking today? 🔵 (Stay in the Excel Matrix) or 🔴 (Start your first script)? #PythonMatrix #DataNeo #SupplyChainRevolution #AutomationMagic #PandasPower #CareerChoice #LogisticsTech
To view or add a comment, sign in
-
-
import pandas as pd data= { 'Name' : ['dhananjay','preeti', 'shambhu'], 'age' : [50,40,15], 'DOB' : [10,30,24] } df=pd.DataFrame(data) This code snippet initializes a small dataset and displays its structural summary using the #Python #pandas library. Step-by-Step Code Explanation import pandas as pd: Imports the pandas library and assigns it the alias pd, which is the standard convention for accessing its functions. data = { ... }: Creates a Python #dictionary where keys represent column headers ('Name', 'age', 'DOB') and values are lists of data points associated with those headers. df = pd.DataFrame(data): Converts the dictionary into a DataFrame object—a two-dimensional, table-like structure—and assigns it to the variable df. df.info(): Executes a method that prints a concise technical summary of the DataFrame structure directly to the console. --------------------------------------- Understanding the Output Window When we run df.info(), the output provides a metadata report for our table: <class 'pandas.core.frame.DataFrame'>: Confirms that our variable df is indeed a Pandas DataFrame object. RangeIndex: Shows the index of the rows (0 to 2, indicating 3 total rows). Data columns: Lists the columns by name and displays: Non-Null Count: Indicates that all 3 rows have valid data (no missing or NaN values). Dtype: Shows the data type for each column; 'Name' will likely be object (text), while 'age' and 'DOB' will be int64 (integers). dtypes & memory usage: Summarizes the count of different data types used and estimates the amount of RAM the DataFrame is occupying. SkillCourse CoDing SeeKho
To view or add a comment, sign in
-
-
📘 Day 7 – Understanding Dictionaries, Tuples & Sets in Python So far in this journey, we’ve already explored lists — how to store, access, and manipulate ordered data. Today, we move a step further by understanding three other powerful Python data structures: Dictionaries, Tuples, and Sets. 🔹 1. Dictionary (key-value pairs) Think of a dictionary like a real-life glossary 📖 — each word (key) has a meaning (value). Example: student = { "name": "Abiodun", "track": "AI/ML", "day": 7 } ✔ Stores data in key-value format ✔ Fast lookup using keys ✔ Very useful for structured data (e.g., user profiles, configs) 🔹 2. Tuple (ordered but immutable) Tuples are like lists, but cannot be changed after creation. Example: coordinates = (10, 20) ✔ Ordered ✔ Cannot add/remove items ✔ Faster and safer for fixed data 🔹 3. Set (unique, unordered collection) Sets automatically remove duplicates. Example: numbers = {1, 2, 2, 3, 4} # Output: {1, 2, 3, 4} ✔ No duplicate values ✔ Unordered ✔ Useful for filtering unique items 💡 Quick Comparison - List → Ordered, changeable - Tuple → Ordered, not changeable - Set → Unordered, no duplicates - Dictionary → Key-value pairs #Python #DataStructures #AIJourney #M4ACE #M4ACELearningChallenge #LearningInPublic
To view or add a comment, sign in
Explore related topics
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