Python Forum

Full Version: convert list to five columns dataframe in sequence
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to programming and python, need help to convert the list to five columns Dataframe , but keep the sequences Huh Huh


small sample from my list:

list_of_cats = ["cat1","cat2","blue","color","coffe","mary","David","dog","clever","stupid",1,2,3,4,5,"A","b","c","d","e"]
five columns dataframe
like this:

"cat1","cat2","blue","color","coffe"
"mary","David","dog","clever","stupid"
1,2,3,4,5
"A","b","c","d","e"


thank a lot Rolleyes Rolleyes
import pandas as pd
import numpy as np

list_of_cats = ["cat1","cat2","blue","color","coffe","mary","David","dog","clever","stupid",1,2,3,4,5,"A","b","c","d","e"]
df = pd.DataFrame(np.array(list_of_cats).reshape(4,5))
print(df)
Output:
0 1 2 3 4 0 cat1 cat2 blue color coffe 1 mary David dog clever stupid 2 1 2 3 4 5 3 A b c d e
thank Big Grin Big Grin Big Grin