I am creating a polar plot with the following code.
import plotly as pt
import plotly.express as px
import pandas as pd
df = pd.read_csv('newdata.csv')
range_num = list(range(100,181, 5))
options = ['NOT_VISIBLE', 'NOT_POSSIBLE', 'ABOVE_LIMIT']
all_options = incompletes + ([str(num) for num in range_num])
dfnew = df.drop(['IDENT', 'LOCATION', 'MONTH', 'AGE'], axis = 1)
df['PT'] = dfnew.ffill(axis='columns').iloc[:, -1]
data = df.groupby('AGE')['PT'].value_counts().reset_index(name='COUNT')
fig = px.line_polar(data, r="COUNT", theta="PT", color="AGE", line_close=True,
color_discrete_sequence=px.colors.sequential.Plasma_r)
fig.show()
This shows a polar plot with two sets of data being plotted for AGE=YES and AGE=NO (YES and NO being the two values in the AGE column). My issue here is that the data around the polar plot is disorganised. I would like the top to start with NOT_VISIBLE
then going clockwise, follow with NOT_POSSIBLE
ABOVE_LIMIT
and the numbers in ascending order (100, 105, 110 etc).
I am sure there is a straightforward way to do this but I am new to python and can't seem to figure it out.
I tried to do:
SC = sorted(['PT'])
But this has not worked, not sure what else to try, any help is greatly appreciated.
Python 2.7 and PANDAS 0.24.2
EDIT: Data below (Actual data contains a lot more rows).
pd.DataFrame({'IDENT': {0L: 'ID76', 1L: 'ID34', 2L: 'ID51', 3L: 'ID97', 4L: 'ID73', 5L: 'ID14', 6L: 'ID64', 7L: 'ID10', 8L: 'ID32', 9L: 'ID89', 10L: 'ID27', 11L: 'ID19', 12L: 'ID80', 13L: 'ID71', 14L: 'ID08', 15L: 'ID47', 16L: 'ID66', 17L: 'ID23'}, 'AGE': {0L: 'YES', 1L: 'NO', 2L: 'YES', 3L: 'NO', 4L: 'NO', 5L: 'NO', 6L: 'YES', 7L: 'YES', 8L: 'YES', 9L: 'NO', 10L: 'YES', 11L: 'YES', 12L: 'NO', 13L: 'YES', 14L: 'NO', 15L: 'NO', 16L: 'YES', 17L: 'YES'}, 'MONTH': {0L: 1990L, 1L: 2000L, 2L: 2010L, 3L: 2020L, 4L: 2020L, 5L: 2010L, 6L: 2000L, 7L: 1990L, 8L: 2020L, 9L: 2010L, 10L: 1990L, 11L: 2020L, 12L: 2000L, 13L: 2010L, 14L: 1990L, 15L: 2020L, 16L: 2000L, 17L: 1990L}, 'LOCATION': {0L: 'E1', 1L: 'E4', 2L: 'E2', 3L: 'E1', 4L: 'E3', 5L: 'E4', 6L: 'E3', 7L: 'E1', 8L: 'E2', 9L: 'E1', 10L: 'E2', 11L: 'E3', 12L: 'E2', 13L: 'E1', 14L: 'E4', 15L: 'E3', 16L: 'E4', 17L: 'E2'}, 'PT5': {0L: nan, 1L: 'ABOVE_LIMIT', 2L: nan, 3L: nan, 4L: nan, 5L: nan, 6L: nan, 7L: nan, 8L: '100', 9L: nan, 10L: nan, 11L: nan, 12L: 'NOT_POSSIBLE', 13L: nan, 14L: nan, 15L: nan, 16L: '165', 17L: 'NOT_POSSIBLE'}, 'PT4': {0L: '110', 1L: nan, 2L: '145', 3L: nan, 4L: 'NOT_VISIBLE', 5L: nan, 6L: '105', 7L: nan, 8L: nan, 9L: nan, 10L: 'ABOVE_LIMIT', 11L: nan, 12L: nan, 13L: nan, 14L: 'NOT_VISIBLE', 15L: nan, 16L: nan, 17L: '130'}, 'PT3': {0L: nan, 1L: 'NOT_POSSIBLE', 2L: nan, 3L: nan, 4L: nan, 5L: nan, 6L: nan, 7L: 'NOT_POSSIBLE', 8L: nan, 9L: nan, 10L: nan, 11L: 'NOT_VISIBLE', 12L: nan, 13L: nan, 14L: nan, 15L: nan, 16L: nan, 17L: nan}, 'PT2': {0L: nan, 1L: nan, 2L: nan, 3L: '160', 4L: nan, 5L: nan, 6L: nan, 7L: '180', 8L: 'NOT_VISIBLE', 9L: nan, 10L: '160', 11L: nan, 12L: nan, 13L: nan, 14L: nan, 15L: nan, 16L: nan, 17L: 'ABOVE_LIMIT'}, 'PT1': {0L: nan, 1L: nan, 2L: nan, 3L: nan, 4L: 'ABOVE_LIMIT', 5L: nan, 6L: nan, 7L: nan, 8L: nan, 9L: nan, 10L: nan, 11L: nan, 12L: '115', 13L: nan, 14L: nan, 15L: nan, 16L: nan, 17L: nan}})
+-------+----------+-----+-------+------+------+-------+------+--------------+
| IDENT | LOCATION | AGE | MONTH | PT1 | PT2 | PT3 | PT4 | PT5 |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID76 | E1 | YES | 1990 | | | | 110 | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID34 | E4 | NO | 2000 | | | NOT_POSSIBLE | ABOVE_LIMIT |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID51 | E2 | YES | 2010 | | | | 145 | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID97 | E1 | NO | 2020 | | 160 | | | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID73 | E3 | NO | 2020 | ABOVE_LIMIT | | NOT_VISIBLE |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID14 | E4 | NO | 2010 | | | | | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID64 | E3 | YES | 2000 | | | | 105 | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID10 | E1 | YES | 1990 | | 180 | NOT_POSSIBLE | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID32 | E2 | YES | 2020 | | NOT_VISIBLE | | 100 |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID89 | E1 | NO | 2010 | | | | | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID27 | E2 | YES | 1990 | | 160 | | ABOVE_LIMIT |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID19 | E3 | YES | 2020 | | | NOT_VISIBLE | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID80 | E2 | NO | 2000 | 115 | | | | NOT_POSSIBLE |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID71 | E1 | YES | 2010 | | | | | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID08 | E4 | NO | 1990 | | | | NOT_VISIBLE |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID47 | E3 | NO | 2020 | | | | | |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID66 | E4 | YES | 2000 | | | | | 165 |
+-------+----------+-----+-------+------+------+-------+------+--------------+
| ID23 | E2 | YES | 1990 | | ABOVE_LIMIT | 130 | NOT_POSSIBLE |
+-------+----------+-----+-------+------+--------------+------+--------------+