Home > other >  O great god look at why this has been an error
O great god look at why this has been an error

Time:10-22


I want to add a new column called user_type, if install_month=log_month assignment of new, old, or assignment tried a lot of methods has been an error, and the correct approach is what? by the way, why the payment and other header is not in the same row -

CodePudding user response:

Card for two days really don't know how make, just registered a number to post for help

CodePudding user response:

Because it is over, installmonth and logmonth userid is your grouping conditions, payment is your query column,

CodePudding user response:

 import pandas as pd 
The from pandas import DataFrame


Frame=DataFrame ({" a ": hc-positie [1], 'b' :,3,5,6 [5]})
Frame/' c '=frame. The apply (lambda x:' new 'if x==[' a'] x [' b '] else 'old' axis=1)
Print (frame)

CodePudding user response:

refer to the second floor of joy pig response:
because userid, installmonth and logmonth, is your grouping conditions, payment is your query column,

That excuse me, how can I put the three also added to the dataframe dpuu inside? I do like this or shows dataframe only a list then an error
Dpuu=pd. DataFrame (dpu_. Groupby ([' user_id ', 'install_month', 'log_month']) [' payment ', 'user_id', 'install_month', 'log_month]. The sum ())
Dpuu [' user_type ']=dpuu. Apply (lambda x: 'new' if x==[' install_month] x [' log_month] else 'old' axis=1)
Finally shows the
KeyError: (' install_month ', 'occurred at index (3, (2013, 4), (2013, 6))')

CodePudding user response:


My original intention is to put the dpu_ the exterior-interior use_rid install_month, log_month one merged into the same lines and then payment aggregation, and then on the first floor of the operation, but only after the groupby payment into a list of all conditions,,,
  • Related