Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
months = tx_retention.columns[2:]
retention_array = []
for i in range(len(months)-1):
    retention_data = {}
    selected_month = months[i+1]
    prev_month = months[i]
    retention_data['InvoiceYearMonth'] = int(selected_month)
    retention_data['TotalUserCount'] = tx_retention[selected_month].sum()
    retention_data['RetainedUserCount'] = tx_retention[(tx_retention[selected_month]>0) & (tx_retention[prev_month]>0)][selected_month].sum()
    retention_array.append(retention_data)


What I have tried:

Tried with astype(int)

But I am receiving error as
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9372/2970800792.py in <module>
----> 1 for i in range(len(months)-1):
      2     retention_data = {}
      3     selected_month = months[i+1]
      4     prev_month = months[i]
      5     retention_data['InvoiceYearMonth'] = astype(selected_month)

TypeError: 'int' object is not callable
Posted
Updated 15-Aug-22 3:52am
v2
Comments
Richard MacCutchan 15-Aug-22 9:48am    
What does months contain after the statement months = tx_retention.columns[2:]?

1 solution

Python
retention_data['InvoiceYearMonth'] = astype(selected_month)

You cannot use the astype function in this way. See pandas.DataFrame.astype — pandas 1.4.3 documentation[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900