CSV to XML – How to Convert in Python?

Problem Formulation Input: You have some data in a CSV file stored in ‘my_file.csv’ where the first row is the header and the remaining rows are values associated to the column names in the header. Name,Job,Age,Income Alice,Programmer,23,110000 Bob,Executive,34,90000 Carl,Sales,45,50000 Desired Output: You want to store the data in an XML file ‘my_file.xml’ so that each … Read more

np.argsort() — A Simpe Illustrated Guide

In Python, the numpy.argsort() function returns the indices that would sort an array in ascending order.  Here is the argument table of the numpy.argsort() function. If it sounds great to you, please continue reading, and you will fully understand the numpy.argsort() function through Python code snippets and vivid visualization. This tutorial is about numpy.argsort() function.  … Read more

How to Skip a Line in Python using \n?

Summary: Python’s newline character \n indicates the end of a line of text. The built-in print() function automatically adds a newline character \n at the end. You can customize this behavior of separating two lines using a single newline character ‘\n’ by changing the default end=’\n’ argument of the print() function to your desired string. … Read more

Ten Best Python 3 Online Compilers [Visual List]

Do you want to run your Python 3 script online? These are the 10 best Python compilers online: #1 – Repl.it Online Python 3 Compiler 🌍 Link: https://repl.it/languages/python3 #2 – Programiz Online Python 3 Compiler 🌍 Link: https://www.programiz.com/python-programming/online-compiler/ #3 – OnlineGDB Python 3 Compiler 🌍 Link: https://www.onlinegdb.com/online_python_compiler #4 – Online-Python.com Compiler 🌍 Link: https://www.online-python.com/ #5 … Read more

How to Extend a Dictionary in Python

Problem Formulation and Solution Overview In this article, you’ll learn how to extend a Dictionary in Python. To make it more fun, we have the following running scenario: Weddings-911, an Event Planner start-up, has just booked three (3) new clients and is hoping for many more! This data is saved to the Dictionary weddings. Beth, … Read more

Spearman Rank Correlation in Python

A prerequisite for a Pearson correlation is normal distribution and metrical data. If your data is not normally distributed or you have variables with ordinal data (like grades, or a Likert scale or a ranked variable from β€œlow” to β€œhigh”) you can still calculate a correlation with the Spearman rank correlation. This can be done … Read more

Python foreach Loop

πŸ’‘ Question: Does Python have a for each or foreach loop? If so, how does it work? If not, what is the alternative? This article will shed light on these questions. I’ll give you the summary first and dive into the details later: Python has three alternatives to the “for each” loop: A simple for … Read more

17 Ways to Read a CSV File to a Pandas DataFrame

πŸ’¬ Question: How to import a CSV file to a Pandas DataFrame in Python? This article will discuss the most interesting examples to read a CSV file to a Pandas DataFrame. If not specified otherwise, we use the following CSV file for all examples: my_file.csv: Name,Job,Age,Income Alice,Programmer,23,110000 Bob,Executive,34,90000 Carl,Sales,45,50000 Let’s get started! Example 1 – … Read more