问题
I am using pandas
in python. I have several Series indexed by dates that I would like to concat into a single DataFrame, but the Series are of different lengths because of missing dates etc. I would like the dates that do match up to match up, but where there is missing data for it to be interpolated or just use the previous date or something like that. What is the easiest way to do this?
回答1:
If the Series are in a dict data
, you need only do:
frame = DataFrame(data)
That puts things into a DataFrame and unions all the dates. If you want to fill values forward, you can call frame = frame.fillna(method='ffill')
.
来源:https://stackoverflow.com/questions/11298097/concatenating-timeseries-of-different-lengths-using-pandas