One possible method to form a dataframe using two lists is to use the pandas library in Python. Here's an example code:
import pandas as pd
# Create two lists of data
list1 = [1, 2, 3]
list2 = ['A', 'B', 'C']
# Combine the lists into a dictionary
data = {'col1': list1, 'col2': list2}
# Create the dataframe using the dictionary
df = pd.DataFrame(data)
# Display the dataframe
print(df)
Output:
col1 col2
0 1 A
1 2 B
2 3 C
In this example, the two lists list1
and list2
are combined into a dictionary called data
, where the keys are the column names and the values are the data for each column. Then, the dataframe df
is created using the pd.DataFrame()
function, passing the data
dictionary as argument. Finally, the dataframe is displayed using the print()
function.
Asked: 2021-08-03 11:00:00 +0000
Seen: 11 times
Last updated: Aug 26 '21