0

I have a dataframe like below

textdata

   id   user_category   operator   circle  
0  23       1           vodafone   mumbai  
1  45       2           airtel     andhra  
2  65       3           airtel     chennai  
3  23       6           vodafone   mumbai  
4  45       1           airtel     gurgaon  
5  65       3           airtel     ongole  
6  23       4           vodafone   mumbai  
7  45       1           airtel     telangana  
8  65       3           airtel     chennai  

In my data 1,2,4,6 in user category is transactional and 3 in user_category is promotional data.So i have divided that by using the following commands

transactional = textdata[textdata['user_category'].isin([1,2,4,6])]
promotional = textdata[textdata['user_category'].isin([1])]

so i got the output for transactional and promotional like below

transactional

   id   user_category   operator   circle  
0  23       1           vodafone   mumbai  
1  45       2           airtel     andhra      
3  23       6           vodafone   mumbai  
4  45       1           airtel     gurgaon  
6  23       4           vodafone   mumbai  
7  45       1           airtel     telangana  

promotional

    id   user_category   operator   circle 
 2  65       3           airtel     chennai  
 8  65       3           airtel     chennai 
 5  65       3           airtel     ongole  

but what i am expecting is to order the index Expected output:

transactional

   id   user_category   operator   circle  
0  23       1           vodafone   mumbai  
1  45       2           airtel     andhra      
2  23       6           vodafone   mumbai  
3  45       1           airtel     gurgaon  
4  23       4           vodafone   mumbai  
5  45       1           airtel     telangana  

promotional

    id   user_category   operator   circle 
 1  65       3           airtel     chennai  
 2  65       3           airtel     chennai 
 3  65       3           airtel     ongole  

this is how i tried for that

transactional.reset_index(inplace = True)

And this is how i got

transactional

    index  id   user_category   operator   circle  
 0    0    23       1           vodafone   mumbai  
 1    1    45       2           airtel     andhra      
 2    3    23       6           vodafone   mumbai  
 3    4    45       1           airtel     gurgaon  
 4    6    23       4           vodafone   mumbai  
 5    7    45       1           airtel     telangana  

But i am expecting in the following way

transactional

   id   user_category   operator   circle  
0  23       1           vodafone   mumbai  
1  45       2           airtel     andhra      
2  23       6           vodafone   mumbai  
3  45       1           airtel     gurgaon  
4  23       4           vodafone   mumbai  
5  45       1           airtel     telangana  

Please help me how can i do this.

But don't suggest me like this way

del transactional['index']

Thanks in advance

1 Answer 1

1

Use the drop=True option of reset_index.

drop : boolean, default False. Do not try to insert index into dataframe columns. This resets the index to the default integer index

So, instead of calling:

transactional.reset_index(inplace = True)

Do:

transactional.reset_index(inplace = True, drop=True)
Sign up to request clarification or add additional context in comments.

1 Comment

can you tell me in detail .what i mean is can you include your code in reset_index command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.