-1

I'm trying to run a for loop with specific intervals. It's a big data file and I need the cumulative sum to a specific number of every single product. In the last column I can see when a new Product starts.

For example:

Specific sum for second Product, 7: 6.1 + 1.0 > 7 --> mark this row (1.0) and jump to the next Product with Change '1'.

for i in range (0, 3):
    ....
    ....


DATE         PRODUCT        PRICE   Change
01.01.2017   NEG_00_12       2.0      0
01.01.2017   NEG_00_12       8.9      0
01.01.2017   NEG_12_24       6.1      1
01.01.2017   NEG_12_24       1.0      0
01.01.2017   NEG_12_24       2.3      0
02.01.2017   NEG_00_12       4.1      1
02.01.2017   NEG_00_12       5.0      0
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Hi and welcome to StackOverflow. You could improve your question by showing what you tried and why that didn't match the expected output – Jondiedoop Feb 17 '19 at 18:39
  • Possible duplicate of [Pandas group-by and sum](https://stackoverflow.com/questions/39922986/pandas-group-by-and-sum) – Nico Albers Feb 17 '19 at 18:40
  • Sry, but I need to be able to sum up to a specific number, for example: Price1: 7 Therefor 6.1 + 1.0 > 7 --> mark this row (1.0) and jump to the next Product with Change '1'. – Jannic Nagel Feb 17 '19 at 18:45
  • val = pd.Index(df.PRICE.cumsum()).get_loc(7, 'backfill') Price_maxmin = df.get_value(val, 'CAPACITY') So I get the value of another column of the row with cumsum >7 – Jannic Nagel Feb 17 '19 at 18:54

1 Answers1

0

if 'df' is the variable to which your data frame is assigned:

df1 = df.groupby('PRODUCT').sum()

df1.reset_index(drop=True)

for idx, row in df1.iterrows():
    print("Price {}: {}".format(idx, row.PRODUCT)
user11075263
  • 41
  • 1
  • 4
  • It says 'DataFrame' object is not callable (df1). I added a new column, when it says '1' a new loop needs to begin, but how can i do this? – Jannic Nagel Feb 17 '19 at 18:33