python - Sort data frame in Pandas and draw a bar graph -
i have result data frame , want sort index column of result data frame. result data frame stores groupby operatation performed
here output of result data frame.
i want sort index column. data types of column int64. right short data alphabets. want draw bar graphs sorted data.
you index contains string representations of dates/periods first need converted before sorting.
result['dates'] = [dt.datetime.strptime(d, "%b %y") d in result.index] result.sort('dates', inplace=true)
to remove column,
result.drop('dates', inplace=true, axis=1)
to use pandas periods (which plotting data):
result['periods'] = [pd.period(dt.datetime.strptime(d, "%b %y"), "m") d in result.index]
to set index:
result = result.reset_index().set_index('periods')
Comments
Post a Comment