I mentioned last week that I recently discovered that in Python, we can read and write files without using pandas. I also spoke briefly about the different file modes that can be used to achieve this and shared a link to the code.(Link to post: https://lnkd.in/dVNYXsAf) In that post, I worked with a CSV file. However, this time around, I wrote to and read from a JSON file still without using pandas. Here is a brief step-by-step explanation of how I did it: ✔️ First, I imported the necessary libraries: Faker (for generating dummy data) and json (for writing data to the JSON file). ✔️Then, I created a few variables for different purposes: => output –> to create a new JSON file and open a connection for writing the generated data. => fake –> to hold the records generated by the Faker library. => alldata –> an empty dictionary that temporarily stores the dummy data before inserting it into a record list. ✔️After creating these variables, I used a loop to generate and insert data from the fake variable into the alldata dictionary. ✔️Finally, I used json.dump to move the data from alldata into the output file and closed the connection. Here is a snapshot of the code and a link to the full script where I wrote and read from a JSON file. Link to full script: https://lnkd.in/dG88jyAa #DataEngineering #Python #PythonModes #JSON #JSONFiles #github
Modupe Afolabi-Jombo’s Post
More Relevant Posts
-
📊 Day 39 | Show Data in Table Using Python (Tkinter + Treeview) #100DaysLearningChallenge Today, I learned how to display tabular data inside a Python GUI using Tkinter’s Treeview widget — and it looks amazing! 😍 🧠 Simple Explanation Ever wondered how to show data like a spreadsheet or database table inside your Python window? Tkinter makes it super easy using the Treeview widget from the ttk module. ⚙️ How It Works 🪄 Step 1: Prepare the Data Create your column names and data: Columns: Item ID, Product Name, Price, Stock Data: Each row stored as a tuple in a list Example: ("101", "Laptop", 75000, 10) ("102", "Mouse", 1200, 50) 🪟 Step 2: Create the Main Window Use tk.Tk() to create the main window Set its title and size 🧩 Step 3: Create the Table Widget Use: tree = ttk.Treeview(root, columns=columns, show='headings') columns → defines your table headers show='headings' → removes the extra blank column height → defines visible rows 🏗️ Step 4: Set Up the Columns Loop through each column and: Set heading titles Define column width and alignment 📥 Step 5: Insert the Data Use: tree.insert('', tk.END, values=item) Each tuple in your data list becomes a row in the table! '' means it’s a standalone row (not a tree structure). 💻 Step 6: Display the Table Use .grid(sticky='nsew') to show the table properly and make it expand when resizing the window. 🎯 Final Output A neat, scrollable table showing your product list, prices, and stock — just like a mini inventory dashboard! Perfect for: ✔️ Displaying database records ✔️ Inventory or billing systems ✔️ Student/project data management 💻 Code Link: https://lnkd.in/d_8sZy9c 🙏 Special thanks to Saurabh Shukla Sir for explaining Tkinter in such a simple and practical way! #100DaysLearningChallenge #Python #Tkinter #GUI #Treeview #PythonProjects #Day39 #Learning #CodingJourney #BeginnerFriendly #PythonDevelopment
To view or add a comment, sign in
-
-
Daily Progress — Python + SQL Today, I practiced some simple but powerful Python basics: 🔹 input() function 🔹 Data types 🔹 String conversion and len() 🔹 Conditional statements (if-else) 🔹 String replacement using .replace() Python Practice: Age = 323 x = len(str(Age)) if x < 2: print("Yes, it is") else: print(x, "- No, it is not") phone_Num = "123-475-886" print(phone_Num.replace("-", "/")) And to make sure I don’t forget SQL while learning Python, I practiced one query today as well WITH CTE AS ( SELECT s.Category, SUM(s.Price * s.Quantity) AS Total_Revenue, SUM(s.Quantity * p.Cost) AS Total_Cost FROM Sales AS s INNER JOIN Products AS p ON s.Product_Name = p.Product_Name GROUP BY s.Category ) SELECT Category, Total_Revenue, Total_Cost, (Total_Revenue - Total_Cost) AS Total_Profit FROM CTE ORDER BY Category, Total_Profit DESC; Lesson learned: Small consistent practice builds long-term mastery. #Python #SQL #DataAnalytics #LearningJourney #DataScience #AI #CodingEveryday #Consistency
To view or add a comment, sign in
-
From SQL to Python, If you’ve ever switched between SQL and Python for data analysis, you know the pain of translating queries into pandas syntax. That’s why I love this quick reference guide It shows how common SQL operations map directly to Python pandas from filtering and grouping to joins and unions. Here are a few gems: 🔹 WHERE → df[df['column'] == 'value'] 🔹 ORDER BY → df.sort_values(by='column') 🔹 JOIN → pd.merge(table1, table2, on='key') 🔹 UNION ALL → pd.concat([table1, table2]) Simple. Powerful. Pythonic. Save this post for your next data project and make switching between SQL and Python effortless.
To view or add a comment, sign in
-
-
🚀 Mastering CSV Files with Pandas in Python! 🐍 If you’re working with data in Python, chances are you’ve come across CSV files 📊 — they’re simple, lightweight, and everywhere! Luckily, Pandas makes handling CSVs super easy and powerful. Here are some key functions you should know 👇 🔹 1️⃣ Read CSV file import pandas as pd df = pd.read_csv('data.csv') 👉 Reads your CSV file into a DataFrame in just one line! 🔹 2️⃣ Write to CSV file df.to_csv('output.csv', index=False) 👉 Saves your processed data back into a CSV file — clean and ready to share! 🔹 3️⃣ Explore data quickly df.head() df.info() df.describe() 👉 Get a quick overview of your dataset before diving deeper. 🔹 4️⃣ Handle Missing Data df.dropna() # Remove missing values df.fillna(0) # Replace missing values 👉 Clean data = Better insights! 💡 Whether you're analyzing sales data, cleaning logs, or preparing ML datasets — Pandas + CSV is your best friend! ❤️ #Python #Pandas #DataScience #MachineLearning #DataAnalytics #CSV #Coding #100DaysOfCode #PythonDevelopers #LearnWithMe 🧠📈💻
To view or add a comment, sign in
-
-
💡 Python Data Types — The Foundation of Every Program! 🐍 Understanding data types is the first step to mastering Python. Here’s a quick breakdown of the major ones 👇 🔹 1️⃣ Numeric Data Type Includes: int → Whole numbers (e.g., 10, -5) float → Decimal numbers (e.g., 3.14, -0.5) complex → Numbers with real and imaginary parts (e.g., 2 + 3j) 🔹 2️⃣ Boolean Data Type Represents truth values: True or False Often used in conditions and logical operations 🔹 3️⃣ Sequential Data Type Includes: String (str) → Sequence of characters (e.g.,"Hello") List → Ordered & changeable collection (e.g.,[1, 2, 3]) Tuple → Ordered but unchangeable collection (e.g.,(1, 2, 3)) 🔹 4️⃣ Container Data Type Includes: Set → Unordered & unique elements (e.g.,{1, 2, 3}) Dictionary (dict) → Key-value pairs (e.g.,{'name': 'Ankita', 'age': 22}) ✨ Each data type in Python is designed for specific use cases — knowing when to use which one makes your code efficient and clean! #Python #LearningPython #DataTypes #CodingJourney #PythonDeveloper #Programming
To view or add a comment, sign in
-
After spending years in real-world Python work, one truth stands out clearly… Your code becomes cleaner, faster, and far easier to debug the moment you truly understand the behaviour of basic data structures. Not the fancy stuff. Not the advanced libraries. Just the fundamentals — lists, sets, and dictionaries. Because most real-world mistakes don’t happen in complex ML models… they happen in simple lines like append(), pop(), remove(), or forgetting how sets treat duplicates. This chart is a good reminder. Lists when you need order and flexibility. Sets when you want uniqueness and lightning-fast lookups. Dictionaries when you need structure and meaning. Master these, and suddenly your Python logic starts making sense — your scripts break less, your confidence grows, and your time-to-solution becomes unbelievably faster. Sometimes levelling up is not about learning more. It’s about understanding what you already use every day — deeply. If you’re learning data analytics and you want clarity in exactly how to think, not just what to type , I’ve created simple, practical learning kits and resources based on real project experience. check link Here https://lnkd.in/gasgBQ6k #DataAnalyst #DataScience #Python #DataJourney #PowerBi #SQL
To view or add a comment, sign in
-
-
𝗣𝘆𝘁𝗵𝗼𝗻 𝗶𝗻 𝗘𝘅𝗰𝗲𝗹 Python is not replacing Excel formulas — it simply makes some things easier or even possible. If you ask whether it’s worth using Python with Excel, I’d say definitely YES — but only when you really need it. For simple tasks like XLOOKUP() or SUMPRODUCT(), and when you’re working with a single file, 𝐄𝐱𝐜𝐞𝐥 is enough. But if you need to merge multiple files, 𝐏𝐲𝐭𝐡𝐨𝐧 can make the process much faster and more reliable. Now, about Python in Excel — here are some of my first insights: 👌 Great to explore and understand how Python code works directly inside Excel. 📈 Python plotting libraries offer many chart types and a lot of control — but the code can be quite complex to write. 𝄜 You can merge tables within the same workbook. ‼️ You cannot open or merge external Excel files, and you cannot write data to external files. In this case use Python outside. Have you tried Python in Excel yet? What’s been your experience so far🧐 #Python #DataAnalyst #BusinessAnalyst #Excel #ExcelTips #ExcelwithPython #MergeFiles #List #Python #PythonInExcel
To view or add a comment, sign in
-
Data Analysis with Python — Beginner Friendly Guide 📊🐍 Data analysis means turning raw data into clear answers. A single-stop, beginner-friendly guide that covers every essential concept for data analysis in Python from zero knowledge to practical skills. Includes step-by-step explanations, runnable examples, common pitfalls, quick cheats, and exercises you can publish on dev.to. What you need Python 3.8+; install via python.org or use Anaconda for bundled scientific packages. Recommended editors: VS Code or JupyterLab / Jupyter Notebook for interactive work. Install key packages: numpy, pandas, matplotlib, seaborn. Install commands pip install numpy pandas matplotlib seaborn notebook # or with conda conda install numpy pandas matplotlib seaborn notebook Start a notebook jupyter notebook Data types: int, float, bool, str, None. Collections: list, tuple \(immutable\), dict \(key-value\), set \(unique items\). Comprehensions: concise list/dict/set creation. Functions: def, arguments, return. Iteration: for, while; us https://lnkd.in/gf7GXHZN
To view or add a comment, sign in
-
In school, most of my work was done in #R & #RStudio. As I've spent more time in #Python for various professional work, I end up using #Jupyter notebooks almost daily. One major quality-of-life add I've done is using the "itables" package in Python. RStudio has a great native data explorer that isn't available by default in Jupyter. Using itables makes it super easy to filter, sort, and look at your data without needing to write explicit filtering code. Nothing fancy but so much better than the default table view in Jupyter. https://lnkd.in/giSAYtGR
To view or add a comment, sign in
-
day 41 Code Explanation The given code is written in Python and defines a class cl_1. Here's a breakdown of the code: Class Definition class cl_1(): data = "class variable" - The class cl_1 is defined with a class variable data initialized to "class variable". Constructor (__init__ method) def _init_(self, a, b=5): self.name = a self.age = b self.no = 100 - The __init__ method is a special method that is automatically called when an object of the class is created. - It takes two parameters: a and b (with a default value of 5). - The method initializes three instance variables: name, age, and no. Instance Methods def m_1(self): print("this is instance method") print(f"name={self.name} age={self.age} no={self.no}") print(f"class variable data={cl_1.data}") def m_2(self): print("this is method-2") self.m_1() - Two instance methods are defined: m_1 and m_2. - m_1 prints a message indicating it's an instance method, followed by the values of the instance
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
Well done, darling daughter