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

[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 List to Tuple

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