When I try to use spread(instrumento, precio)
it, it returns an error
Each row of output must be identified by a unique combination of keys. Keys are shared for 851 rows
I need to work with the different instruments, for this I try to take them as variables
fecha instrumento precio
2 2020-04-20 YPFD 397.50
3 2020-04-20 YPFD 397.50
4 2020-04-20 YPFD 397.50
5 2020-04-17 YPFD 401.85
6 2020-04-17 YPFD 402.00
7 2020-04-17 YPFD 401.00
8 2020-04-16 YPFD 400.60
To begin with, with the data you show, it doesn't make sense to make a
spread()
, from what I understand, what you are looking for is that each row is a date and each column an instrument, however it has multiple prices for the same instrument/date and the condition to be able to do aspread
is that there is only one value per row/column, in your case date/instrument. It occurs to me that what you need in the first place is some aggregation function, for example: