Skip to content Skip to sidebar Skip to footer

Length Mismatch In Pandas Dataframe Resampling With Specific Dates

I have tried the code for my own data. It works when I compute the sum. However, If I assign the index to the new dataframe, an error occurred. I noticed that it's because sometime

Solution 1:

In this case, the error is saying that there are only 3 items in custom_sum, whereas custom_dates lists 4 dates. Removing the errant date (datetime.date(2016,2,10) in this case) should solve the dimension issue.

But in general, to save a new DataFrame with only the rows that meet a certain condition, you can use:

new_df = custom_sum[custom_sum.index.isin(custom_dates)]

There's a way to do it with DataFrame.drop() as well. Not sure which is more efficient or desirable. But I would suspect that doing it with df.drop() and using the inplace=True parameter would likely save on memory given that it won't create a new DataFrame object--though someone correct me if I'm wrong on that assumption.

Post a Comment for "Length Mismatch In Pandas Dataframe Resampling With Specific Dates"