Pandas: Convert a given list of lists into a Dataframe
Pandas: DataFrame Exercise-54 with Solution
Write a Pandas program to convert a given list of lists into a Dataframe.
Sample Solution :
Python Code :
import pandas as pd my_lists = [['col1', 'col2'], [2, 4], [1, 3]] # sets the headers as list headers = my_lists.pop(0) print("Original list of lists:") print(my_lists) df = pd.DataFrame(my_lists, columns = headers) print("New DataFrame") print(df)
Original list of lists: [[2, 4], [1, 3]] New DataFrame col1 col2 0 2 4 1 1 3
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework