xxxxxxxxxx
#import module
import pandas as pd
#have your data as a list of lists - they will each be a ROW
data = [['Stanley', 10, 'blue'],
['Kyle', 9, 'green'],
['Kenny', 10, 'orange'],
['Cartman', 10, 'turquoise']]
#convert to Dataframe specifying columns names
df = pd.DataFrame(data, columns=['Name','Age','Hat Color'])
xxxxxxxxxx
import pandas as pd
data = [['New York Yankees', 'Acevedo Juan', 900000, 'Pitcher'],
['New York Yankees', 'Anderson Jason', 300000, 'Pitcher'],
['New York Yankees', 'Clemens Roger', 10100000, 'Pitcher'],
['New York Yankees', 'Contreras Jose', 5500000, 'Pitcher']]
df = pd.DataFrame.from_records(data)
xxxxxxxxxx
# import pandas as pd
import pandas as pd
# list of strings
lst = ['Geeks', 'For', 'Geeks', 'is', 'portal', 'for', 'Geeks']
# list of int
lst2 = [11, 22, 33, 44, 55, 66, 77]
# Calling DataFrame constructor after zipping
# both lists, with columns specified
df = pd.DataFrame(list(zip(lst, lst2)),
columns =['Name', 'val'])
xxxxxxxxxx
Creating Pandas dataframe using list of lists ; df = pd.DataFrame(data, columns = [ 'Name' , 'Age' ])
xxxxxxxxxx
import pandas as pd
# Example list
my_list = [1, 2, 3, 4, 5]
# Create a dataframe from the list
df = pd.DataFrame(my_list)
# Display the dataframe
print(df)
xxxxxxxxxx
col_one_list = df['one'].tolist()
col_one_arr = df['one'].to_numpy()