0

I have data in two different data frames:

First data frame, where binned is a pd.Interval:

    zip     binned                  bin_count
0   07302   (325000.0, 662500.0]    6
1   07302   (662500.0, 1000000.0]   14
2   07302   (1000000.0, 1337500.0]  2
3   07302   (1337500.0, 1675000.0]  3
4   07302   (1675000.0, 2012500.0]  3
5   07302   (2012500.0, 2350000.0]  2

Second data frame:

    zip     listing_close_price price_interest
0   07302   730000.0            0.047237
1   07302   1650000.0           1.000000
2   07302   509000.0            0.032936
3   07302   685000.0            0.044325
4   07302   660000.0            1.000000

Such that my first data frame will have an extra column, because in my second data frame rows 0 and 1 both fall in first data frame index 0 = .07.

Final data frame:

    zip     binned                  bin_count total_price_interest
0   07302   (325000.0, 662500.0]    6         .07
1   07302   (662500.0, 1000000.0]   14
2   07302   (1000000.0, 1337500.0]  2
3   07302   (1337500.0, 1675000.0]  3         .1
4   07302   (1675000.0, 2012500.0]  3
5   07302   (2012500.0, 2350000.0]  2

Thanks in advance!

Unfortunately, I've been going in circles and am unclear about where to start.

accdias
  • 5,160
  • 3
  • 19
  • 31
  • It would be simpler if you split the bin values into separate `bin_start` and `bin_end` columns. – Barmar Nov 14 '22 at 17:53
  • Thanks what makes it easier with that approach? I'm still able to check values in a pd.Interval with a `in` statement – chiggly007 Nov 14 '22 at 17:58
  • Sorry, didn't see that it was an interval value, thought it was a tuple. – Barmar Nov 14 '22 at 18:00
  • Anyway, use the `in` check in a `join` condition. – Barmar Nov 14 '22 at 18:00
  • Thanks, @Barmar. It's the join part where I'm getting hung up on as the df are not the same length. Do you have a example of how it would look? As I would need to perform a sum operation as well. – chiggly007 Nov 14 '22 at 18:02
  • This may be helpful: https://stackoverflow.com/questions/44106304/merging-two-pandas-dataframes-by-interval – Barmar Nov 14 '22 at 18:05
  • Thank you so much @Barmar your idea and the link helped a lot. Thanks again! – chiggly007 Nov 14 '22 at 18:19

0 Answers0