I have this list of dictionaries:
[{
'time': '2022-01-01', 'pl': 0.0, 'accountBalance': 500.0, 'orderID': 500.0}, {
'time': '2022-01-25', 'pl': 6.3505, 'accountBalance': nan, 'orderID': 506.35}, {
'time': '2022-01-26', 'pl': 23.2703, 'accountBalance': 505.9298, 'orderID': 501.03}, {
'time': '2022-01-27', 'pl': 16.68, 'accountBalance': 521.4393, 'orderID': 502.07}, {
'time': '2022-01-28', 'pl': -2.29, 'accountBalance': 519.1493, 'orderID': nan}, {
'time': '2022-01-31', 'pl': -0.89, 'accountBalance': 518.2593, 'orderID': nan
}]
I want to replace nan by the value from the previous row like this :
[{
'time': '2022-01-01', 'pl': 0.0, 'accountBalance': 500.0, 'orderID': 500.0}, {
'time': '2022-01-25', 'pl': 6.3505, 'accountBalance': 500.0, 'orderID': 506.35}, {
'time': '2022-01-26', 'pl': 23.2703, 'accountBalance': 505.9298, 'orderID': 501.03}, {
'time': '2022-01-27', 'pl': 16.68, 'accountBalance': 521.4393, 'orderID': 502.07}, {
'time': '2022-01-28', 'pl': -2.29, 'accountBalance': 519.1493, 'orderID': 502.07}, {
'time': '2022-01-31', 'pl': -0.89, 'accountBalance': 518.2593, 'orderID': 502.07
}]
I tried with Pandas and "df.fillna(method='ffill')" but I have an error saying 'list' object has no attribute 'fillna'. I think it's because it's not a csv.