0

I used following code to get a dataframe groupby table

df1=df.groupby(['timestampEpochSecond'],sort=True)['metricValue'].sum().sort_values(ascending=False)
df_summary=pd.Series.to_frame(df1)

df_summary.reset_index(inplace=True)
df_summary.rename(index=str,columns=    {'timestampEpochSecond':'splunk_query_mins'},inplace=True)
df_summary

The table is like

splunk_query_mins

metricValue

0 2018-12-13 06:41 1200.0

1 2018-12-13 06:07 238.0

2 2018-12-13 06:47 42.0

3 2018-12-13 09:54 14.0

4 2018-12-13 16:40 10.0

5 2018-12-12 21:30 5.0

6 2018-12-13 08:12 3.0

7 2018-12-13 01:11 3.0

8 0 0.0

However, when I used

df1.sort_values(by=''splunk_query_mins',ascending=True)

I got the error TypeError: '>' not supported between instances of 'int' and 'str' Again, thank you so much for helping me

david
  • 45
  • 8

1 Answers1

0

It is possible that the column splunk_query_mins is of the wrong dtype - it is likely a object. I think you will first need to convert splunk_query_mins to datetime. See this SO post, which shows what you might be trying to do.

It probably requires something like this

df1['splunk_query_mins'] = pd.to_datetime(df1.splunk_query_mins)
df1.sort_values(by='splunk_query_mins', ascending=True)

EDIT: If, for some reason, you want to keep the splunk_query_mins column as object (instead of changing it to datetime), then you have to try something like this - replace .ix by .loc.

edesz
  • 11,756
  • 22
  • 75
  • 123