Python Forum
[pandas] How to reshape the list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pandas] How to reshape the list
#1
Hi,
I have blow list, I can reshape it but I want to reshape based on other condition:

#%%
import pandas as pd
import numpy as np
lst = ['A','',3,'A','',0,'A',3,2]
aa = np.reshape(lst,(-1,3))
aa = pd.DataFrame(aa, columns=['A','B','C'])
but I want to break the sub-list at each 'A'
A	B	C
A		3
A		0
A	3	2
I want to break at 'A' because some time columns may change,
if I have a list like:

lst = ['A','',3,'4','A','',0,'2020/07/25 10:13:23','A',3,2,''2020/07/25 10:13:29']
in this case, i need to change np.reshape(lst,(-1,4)), which I want to avoide
Reply


Messages In This Thread
[pandas] How to reshape the list - by Mekala - Jul-25-2020, 02:09 AM
RE: How to reshape the list - by scidam - Jul-25-2020, 03:58 AM
RE: How to reshape the list - by Mekala - Jul-25-2020, 05:25 AM
RE: How to reshape the list - by scidam - Jul-25-2020, 07:50 AM
RE: [pandas] How to reshape the list - by Mekala - Jul-25-2020, 10:16 AM
RE: [pandas] How to reshape the list - by scidam - Jul-26-2020, 12:36 AM
RE: [pandas] How to reshape the list - by Mekala - Jul-26-2020, 12:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issues with Shape/Reshape for CNN moddy10 0 1,428 Oct-12-2021, 03:54 PM
Last Post: moddy10
  Comparing results within a list and appending to pandas dataframe Aryagm 1 2,320 Dec-17-2020, 01:08 PM
Last Post: palladium
  cannot reshape array of size 0 into shape Roro 2 6,194 Jun-14-2020, 11:28 AM
Last Post: Roro
  reshape from 3D to 3D matrix paul18fr 0 1,716 Nov-12-2019, 11:26 AM
Last Post: paul18fr
  Simple numpy reshape error wih contour3D AdeIsHere 0 2,149 Sep-17-2019, 12:01 PM
Last Post: AdeIsHere
  Inserting data from python list into a pandas dataframe mahmoud899 0 2,580 Mar-02-2019, 04:07 AM
Last Post: mahmoud899
  'list' object has no attribute 'reshape' SamSoftwareLtd 1 15,480 Nov-04-2018, 10:38 PM
Last Post: stullis
  List and Dictionaries with Pandas Balinor 3 2,909 Aug-20-2018, 10:47 PM
Last Post: ichabod801
  missing pandas even if in conda list metalray 2 3,402 May-29-2018, 12:52 PM
Last Post: metalray
  1 I cant read many stocks(list) with pandas-datareader from yahoo Davidii111 1 4,907 Dec-27-2017, 04:47 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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