0

folks, I am working on one dataset using pandas I have already found my data according to my need but I am unable to plot it accurately month-wise as my result data is shown in any order and in graph floating using matplotlib library is must be in Jan, Feb, March... order AS shown in the picture I need this data in order like Jan, Feb, March...

enter code here
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pandas as pd
df = pd.read_csv('F:/Downloads/DataSet/starlink_launches.csv',
             encoding='cp1252')

# CREATE MONTHS AND YEAR COLUMNS

df['launch_Month'] = df['launch_date'].str.split(' ').str[1]
df['launch_Year'] = df['launch_date'].str.split(' ').str[2]

# REPLACE DATA FOR EASY ACCESS

df['launch_outcome'] = df['launch_outcome'].str.replace('Success\r\n',
    'Success')

# CREATE DATAFRAME TO STORE RESULTS

result = pd.DataFrame()
result = df[df['launch_outcome'] == 'Success'].groupby('launch_Month'
    ).count()

# DATA VISULIZATION[![enter image description here][1]][1]

import matplotlib.pyplot as plt
import numpy as np

# plt.figure(figsize=(5,5))

Months = range(1, 13)
plt.bar(Months, result['launch_outcome'])

plt.title('Succes ratio of lunch')
plt.ylabel('Number Of launch', fontsize=12)
plt.xlabel('Months', fontsize=12)
plt.xticks(np.arange(1, 13))
plt.grid()
plt.show()

I NEED this data in an,feb,may order

Milan
  • 46
  • 7

1 Answers1

2

Use reindex with calendar module:

import calendar
result['launch_outcome'].reindex(calendar.month_abbr[1:])
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
  • Its Works fine But shows data like Jan Feb..... is there any way I can use the full names like January, February, March... Because in my dataset there is a full name so its so NaN in result part – Milan Dec 22 '21 at 08:05