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 … Read more

How to Convert a List of Lists to a CSV File in Python

Problem: How to convert a list of lists to a csv file? Example: Given is a list of list—for example salary data of employees in a given company: Your goal is to write the content of the list of lists into a comma-separated-values (CSV) file format. Your outfile should look like this: # file.csv Alice,Data … Read more

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

Python Logo

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 … Read more

How to Convert List of Lists to NumPy Array?

Short answer: Convert a list of lists—let’s call it l—to a NumPy array by using the standard np.array(l) function. This works even if the inner lists have a different number of elements. Convert List of Lists to 2D Array Problem: Given a list of lists in Python. How to convert it to a 2D NumPy … 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 … Read more