Python Forum
convert list to five columns dataframe in sequence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert list to five columns dataframe in sequence
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
thank Big Grin Big Grin Big Grin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert dataframe from str back to datafarme Creepy 1 585 Jul-07-2023, 02:13 PM
Last Post: snippsat
  convert string to float in list jacklee26 6 1,818 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,174 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  convert a list to links Pir8Radio 3 1,043 Nov-28-2022, 01:52 PM
Last Post: Pir8Radio
  convert this List Comprehensions to loop jacklee26 8 1,418 Oct-21-2022, 04:25 PM
Last Post: deanhystad
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,641 Aug-19-2022, 11:07 AM
Last Post: dm222
  function returns dataframe as list harum 2 1,337 Aug-13-2022, 08:27 PM
Last Post: rob101
  Using .append() with list vs dataframe Mark17 7 9,906 Jun-12-2022, 06:54 PM
Last Post: Mark17
  Convert list to interger Clives 5 1,542 May-09-2022, 12:53 PM
Last Post: deanhystad
  Convert python dataframe to nested json kat417 1 6,246 Mar-18-2022, 09:14 PM
Last Post: kat417

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020