python - Pandas group the next row after a query -
i'm trying group possible mistaken values in dataframe, this:
df[(df.text == '4,') | (df.text == '85')] i get:
region line text 58 15 2 85 76 0 4 4, 77 0 4 85 80 2 4 4, 81 2 4 85 82 3 4 4, 83 3 4 85 knowing values can group them, this:
df_values = df[(df.text == '4,') | (df.text == '85')] df_values.groupby("line")['text'].apply(''.join).reset_index() the result this:
line text 0 0 4,85 1 2 4,85 2 3 4,85 3 15 85 but need conditionally possible cases, this:
possible[(df.text.str.contains(currency_re)==true) | (df.text.str.contains(re.compile('^([0-9 {2})$')))] i did quick solution this:
possible_currencies.groupby(['region', "line"])['text'] .apply(''.join).reset_index() the downside having possible values, or in same line/region like: 88 product u$: 10,23 grouping be: 8810,23 (bad)
i think best idea might group next row matches criteria.
but have no idea how that.
any thoughts?
Comments
Post a Comment