Untitled
user_3298650655
plain_text
4 years ago
751 B
6
Indexable
import pandas as pd
tr = pd.read_csv('transactions.csv')
customer_id = 70780820
customer_df = tr[tr.customer_id == customer_id].copy()
customer_df['day'] = customer_df.tr_datetime.str.split().str[0].astype(int)
days_amount = customer_df.groupby('day').aggregate({'amount': 'sum'}).sort_values('day')
days_amount
days = [i for i in range(457)]
amount = [0]
for i in range(456):
amount.append(amount[-1] + days_amount.iloc[i])
import matplotlib.pyplot as plt
plt.plot(days, amount)
sum(amount[i: i+30]) / 30
max_d = 0
max_ost = 0
for i in range(0, len(amount) - 30):
mean = (sum(amount[i: i+30]) / 30).iloc[0]
if mean > max_ost:
max_ost = mean
max_d = i
print('макс с ', i, 'по', i + 30, 'дни')
Editor is loading...