0

This dataframe is obtained from a timeseries resample operation as shown below

                    Ticket  Priority
Submit Date     
2018-01-02 04:00:00      1  P3 - Normal
2018-01-02 08:00:00     18  P3 - NormalP3 - NormalP3 - NormalP3 - NormalP3...
2018-01-02 12:00:00     23  P2 - HighP3 - NormalP3 - NormalP3 - NormalP3 -...
2018-01-02 16:00:00      1  P3 - Normal
2018-01-02 20:00:00      0  0
2018-01-03 00:00:00      0  0
2018-01-03 04:00:00      1  P3 - Normal
2018-01-03 08:00:00      3  P3 - NormalP3 - NormalP3 - Normal

what I'm looking to get actually is something like this:

                    Ticket  Priority
Submit Date     
2018-01-02 04:00:00      1  P3 - Normal = 1
2018-01-02 08:00:00     18  P3 - Normal = 4
2018-01-02 12:00:00     23  P2 - High   = 1
                            P3 - Normal = 3
2018-01-02 16:00:00      1  P3 - Normal = 1
2018-01-02 20:00:00      0  0
2018-01-03 00:00:00      0  0
2018-01-03 04:00:00      1  P3 - Normal = 1
2018-01-03 08:00:00      3  P3 - Normal = 3

where the Priority column lists the type of ticket and the count of occurrence of each of those ticket types.

1 Answer 1

1
def get_priorities(x):
    types = ['Normal','High']
    if x == 0:
         return 0
    else:
        z = []
        for y in types:
            if y in x:
                z.append(str(x[:2]+ '-' + '{} = '.format(y) + str(x.count(y))))
        return ' '.join(z)

This should be your custom function and use lambda to apply it on your data frame.

df['Priority'] = df['Priority'].apply(lambda x: get_priorities(x))

Let me know if this does not work for you.

Sign up to request clarification or add additional context in comments.

Comments

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.