Month: April 2020

Pandas to_csv()

You can convert a list of lists to a Pandas DataFrame that provides you with powerful capabilities such as the to_csv() method. This is the easiest method and it allows you to avoid importing yet another library (I use Pandas in many Python projects anyways). Output: # file2.csv Alice,Data Scientist,122000 Bob,Engineer,77000 Ann,Manager,119000 You create a …

Pandas to_csv() Read More »

Python Logo

[PDF Collection] 7 Beautiful Pandas Cheat Sheets — Post Them to Your Wall

Pandas is an open-source Python library that is powerful and flexible for data analysis. If there is something you want to do with data, the chances are it will be possible in pandas. There are a vast number of possibilities within pandas, but most users find themselves using the same methods time after time. In this …

[PDF Collection] 7 Beautiful Pandas Cheat Sheets — Post Them to Your Wall Read More »

How to Convert List of Tuples to List of Lists in Python?

If you’re in a hurry, here’s the short answer: use the list comprehension statement [list(x) for x in tuples] to convert each element in your tuples list to a list. This works also for list of tuples with varying number of elements. But there’s more to it and studying the two main method to achieve …

How to Convert List of Tuples to List of Lists in Python? Read More »

How to Convert List of Lists to List of Tuples in Python?

If you’re in a hurry, here’s the short answer: use the list comprehension statement [tuple(x) for x in list] to convert each element in your list to a tuple. This works also for list of lists with varying number of elements. But there’s more to it and studying the two main methods to achieve the …

How to Convert List of Lists to List of Tuples in Python? Read More »

How to Convert List of Lists to a Pandas Dataframe

Problem: You’re given a list of lists. Your goal is to convert it into a Pandas Dataframe. Example: Say, you want to compare salary data of different companies and job descriptions. You’ve obtained the following salary data set as a list of list: How can you convert this into a Pandas Dataframe? DataFrame() Solution: The …

How to Convert List of Lists to a Pandas Dataframe Read More »

How to Convert a List of List to a Dictionary in Python?

For some applications, it’s quite useful to convert a list of lists into a dictionary. Databases: List of list is table where the inner lists are the database rows and you want to assign each row to a primary key in a new dictionary. Spreadsheet: List of list is two-dimensional spreadsheet data and you want …

How to Convert a List of List to a Dictionary in Python? Read More »

Python List of Lists – A Helpful Illustrated Guide to Nested Lists in Python

There’s an element of confusion regarding the term “lists of lists” in Python. I wrote this most comprehensive tutorial on list of lists in the world to remove all those confusions by beginners in the Python programming language. This multi-modal tutorial consists of: Source code to copy&paste in your own projects. Interactive code you can …

Python List of Lists – A Helpful Illustrated Guide to Nested Lists in Python Read More »

Convert Tuple to List

Problem: Given a Python tuple with n elements. How to convert it into a list with the same n elements? Examples: Convert tuple (1, 2, 3, 4, 5) into list [1, 2, 3, 4, 5]. Convert tuple (‘Alice’, ‘Bob’, ‘Ann’) into list [‘Alice’, ‘Bob’, ‘Ann’]. Convert tuple (1,) into list [1]. Note Tuple: Tuples are …

Convert Tuple to List Read More »