Quantcast
Channel: User Bijan - Stack Overflow
Viewing all articles
Browse latest Browse all 99

Check if Series has Values in Range

$
0
0

I have a Pandas dataframe that has user information and also has a column for their permissions:

UserName    PermissionsJohn Doe             02John Doe             11 Example             09 Example             08   User3             11

I am trying to create a new column called User Class that is based on their Permissions (looking at all of the users permissions). If a user has all permissions <10, they are considered Admin. If a user has all permission >=10, they are considered User. However if they have permissions that are both <10 and >=10, then they will be coded as Admin/User. So my resulting output would be:

UserName    Permissions    User ClassJohn Doe             02    Admin/UserJohn Doe             11    Admin/User Example             09         Admin Example             08         Admin   User3             11          User

What would be the best way to do this? My original idea was to do:

for UserName, User_df in df.groupby(by='UserName'):    LT10 = (User_df['Permissions'] < 10).any()    GTE10 = (User_df['Permissions'] >= 10).any()    if (LT10 & GTE10):        UserClass = 'Admin/User'    elif LT10:        UserClass = 'Admin'    elif GTE10:        UserClass = 'User'    df.at[User_df.index, 'User Class'] = UserClass

However these seems very inefficient because df has ~800K records


Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>