xxxxxxxxxx
# import pandas as pd
import pandas as pd
# list of strings
lst = ['Geeks', 'For', 'Geeks', 'is',
'portal', 'for', 'Geeks']
# Calling DataFrame constructor on list
df = pd.DataFrame(lst)
df
xxxxxxxxxx
# import pandas as pd
import pandas as pd
# list of strings
lst = ['fav', 'tutor', 'coding', 'skills']
# Calling DataFrame constructor on list
df = pd.DataFrame(lst)
print(df)
xxxxxxxxxx
import pandas as pd
from pandas import DataFrame
df = DataFrame(lst,columns=['num'])
xxxxxxxxxx
import pandas as pd
# Create a list of data
my_list = [['Alice', 25], ['Bob', 30], ['Charlie', 35]]
# Convert the list to a DataFrame
df = pd.DataFrame(my_list, columns=['Name', 'Age'])
# Print the DataFrame
print(df)
xxxxxxxxxx
L = ['Thanks You', 'Its fine no problem', 'Are you sure']
#create new df
df = pd.DataFrame({'col':L})
print (df)
col
0 Thanks You
1 Its fine no problem
2 Are you sure
xxxxxxxxxx
# Way 1
df.values.tolist()
# Way 2
[list(row) for row in df.iterrows()]
# Way 3
rows = []
with open('dataset.csv') as file :
rows.append(file.readline())
xxxxxxxxxx
import pandas as pd
df = pd.concat(list_of_dataframes)
# easy way
xxxxxxxxxx
import pandas as pd
# Assuming the dataframe is named 'df'
# Convert the entire dataframe to a list
df_list = df.values.tolist()
# Convert specific columns of the dataframe to a list
selected_columns = ['column1', 'column2'] # Replace with the actual column names
selected_columns_list = df[selected_columns].values.tolist()