How  To Make Gant Charts Using Plotly

How To Make Gant Charts Using Plotly

Assume That We Have A Spreadsheet Containing A List Of Tasks Like This


TASK	START	FINISH
TASK A	2021-03-25	2021-03-31
TASK B	2021-03-25	2021-03-31
TASK C	2021-03-31	2021-04-15
TASK D	2021-04-02	2021-04-22
TASK E	2021-04-01	2021-04-05
TASK F	2021-04-22	2021-04-26
TASK G	2021-04-27	2021-05-15H        

Since We Are Using Python3 On Google Colaboratory, We Will Need To Have Access To Google Drive Through Google Colab First, This Could Be Achieved Using This Snippet Of Code.


from?google.colab?import?driv
drive.mount('/content/drive')e        

In Our Case We Are Not Uploading An Excel File To Google Colab, So We Will Not Use The Pandas pd.read_excel , However , We Will Use The Following Snippets


import?plotly.express?as?px
import?pandas?as?pd
from?google.colab?import?aut
auth.authenticate_user()
import?gspread
from?oauth2client.client?import?GoogleCredentialsh        



gc?=?gspread.authorize(GoogleCredentials.get_application_default()


worksheet?=?gc.open('dummy?for?gant?chart?colab').sheet1


#?get_all_values?gives?a?list?of?rows.
rows?=?worksheet.get_all_values()
print(rows)
#?Convert?to?a?DataFrame?and?render.
pd.DataFrame.from_records(rows)
df1?=?pd.DataFrame.from_records(rows))        

We Will Then Rename The Pandas Data Frame To Drop The First Index Row Using This Snippet


#droping?first?row?"index?row"?then?renaming?the?new?data?frame
df1.rename(columns=df1.iloc[0]).drop(df1.index[0])
df2?=?df1.rename(columns=df1.iloc[0]).drop(df1.index[0])?        

Now We Are Ready To Visualize Our Gant Chart


fig?=?px.timeline(df2,?x_start="START",?x_end="FINISH",?y="TASK"
fig.update_yaxes(autorange="reversed")?#?otherwise?tasks?are?listed?from?the?bottom?up
fig.show()        

The Google Colab Note Book Is Down In The First Comment.

Dr.Mostafa Samy, BDS

Dentist | Healthcare Data Science / A.i | Generative A.i for healthcare "clinical LLM's" | Digital Healthcare Transformation & Integration | MSc Operations Research | Applied Statistics(FGSSR) | DTQM( AICPD).

3 年
回复
Dr.Mostafa Samy, BDS

Dentist | Healthcare Data Science / A.i | Generative A.i for healthcare "clinical LLM's" | Digital Healthcare Transformation & Integration | MSc Operations Research | Applied Statistics(FGSSR) | DTQM( AICPD).

3 年
回复

要查看或添加评论,请登录

Dr.Mostafa Samy, BDS的更多文章

社区洞察

其他会员也浏览了