0

I'm looking for code to add [0,0] arrays to the 'Mar' column if the shape is smaller than (3,)

Sample Dataframe visualized:

 df:
  account        Jan      Feb          Mar
Jones LLC  |     150   |   200    | [.332, .326], [.058, .138]
Alpha Co   |     200   |   210    | [[.234, .246], [.234, .395], [.013, .592]]
Blue Inc   |     50    |   90     | [[.084, .23], [.745, .923]]

Again: I'm looking for code to add [0,0] arrays to the 'Mar' column so that any row with shape smaller than (3,x) is modified, resulting in the following df

 df:
  account        Jan      Feb          Mar
Jones LLC  |     150   |   200    | [.332, .326], [.058, .138], [0, 0]
Alpha Co   |     200   |   210    | [[.234, .246], [.234, .395],[.013, .592] 
Blue Inc   |     50    |   90     | [[.084, .23], [.745, .923], [0, 0]

Code to create sample dataframe:

Sample = [{'account': 'Jones LLC', 'Jan': 150, 'Feb': 200, 'Mar': [[.332, .326], [.058, .138]]},
     {'account': 'Alpha Co',  'Jan': 200, 'Feb': 210, 'Mar': [[.234, .246], [.234, .395], [.013, .592]]},
     {'account': 'Blue Inc',  'Jan': 50,  'Feb': 90,  'Mar': [[.084, .23], [.745, .923]]}]
df = pd.DataFrame(Sample)

1 Answer 1

1

You could add extra values,

df['Mar'] = df['Mar']+[[0, 0], [0, 0], [0, 0]]

then trim it down, using a method from here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. Great idea. Not exactly pythonic but it works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.