-1

What I want to be doing looks something like:

index   Price

0      1000 -20
1      500   30
2      200    0

I want to do this because I want to keep track of the price changes? I'm using a ipywidget where I want to use the delta to change the cell color. If delta is > 0 i want the price cell where I display it to be green and < 0 to be red.

Please help!

This is what I want my dataframe to end up looking like

  • 2
    You can have a list in a dataframe column, but I don't think that's really what you want, either... `pd.DataFrame({'Price':[[1000,0],[500,30]]})`. Why not have two columns, one for start and one for end, and then a third with the delta? I'm not familiar with ipywidget, so maybe there is some requirement there. – scotscotmcc May 28 '21 at 02:58
  • I think I could do the separate columns, but I don't want to show the delta or the start column. I'd just want the latest data entry and the cell color would change according to the delta. But I was trying to see if there was any more efficient and easy way of doing this. – user10427488 May 28 '21 at 03:22
  • can you post your expected output from the given sample dataframe? – Anurag Dabas May 28 '21 at 03:34
  • @AnuragDabas I just posted a picture. – user10427488 May 28 '21 at 03:52

1 Answers1

0

you can do this:

a = np.array([2,3,4])
b = np.array([3,4,5])
data = pd.DataFrame(a)
c = np.vstack((a,b)).T
data['ab'] = list(c)
Sudhanshu
  • 704
  • 1
  • 9
  • 24