Relative Content

Tag Archive for pythonpandasnumpy

Pandas fillna(‘value’) followed by df.replace(‘value’,np.nan) not working

For some reason df.replace() is not working for me. I want to fill nan values with a dummy value, pivot, then turn the dummy values back into nans using replace, but replace is not working. On further investigation it seems that the ‘yy’ value is not being recognised as the same as the fillna value so the function cant find anything to replace. e.g.

TypeError: Cannot convert numpy.ndarray to numpy.ndarray

I’m not sure why but after getting a new install of windows and a new pycharm install and trying to run some previously functional code I am now getting the above error with the code below. Is it a setup issue or has something changed that now makes this code not function? Error happens on the last line. The error doesn’t make sense to me as there should be no conversion required for ndarray to ndarray.

Resampling DataFrame with MultiIndex in Pandas for Specific Time Intervals

I have a DataFrame in Pandas with a MultiIndex consisting of two levels (‘market_id’ and ‘runner_id’). The DataFrame contains a column called ‘running’ representing time durations. I want to resample this DataFrame so that it shows intervals of 1 minute starting at 0 days 00:00:00 up until 120 minutes for each combination of ‘market_id’ and ‘runner_id’. I need to interpolate the ‘last_traded_price’ at each minute.