I am looking to convert a normal dataframe with the columns ['Task','Start','Finish','Resource'] into the following format without doing it manually. Please note the = instead of : inbetween column and value... How would I convert this?
df = [dict(Task=“SH 5”, Start=‘2017-01-01’, Finish=‘2017-02-02’, Resource=‘Complete’),
dict(Task=“SH 5”, Start=‘2017-02-15’, Finish=‘2017-03-15’, Resource=‘Incomplete’),
dict(Task=“SH 5”, Start=‘2017-03-15’, Finish=‘2017-04-15’, Resource=‘Not Started’),
dict(Task=“SH 5”, Start=‘2018-03-15’, Finish=‘2018-04-15’, Resource=‘Complete’),
dict(Task=“Job-2”, Start=‘2017-01-17’, Finish=‘2017-02-17’, Resource=‘Not Started’),
dict(Task=“Job-2”, Start=‘2017-01-17’, Finish=‘2017-02-17’, Resource=‘Complete’),
dict(Task=“Job-3”, Start=‘2017-03-10’, Finish=‘2017-03-20’, Resource=‘Not Started’),
dict(Task=“Job-3”, Start=‘2017-04-01’, Finish=‘2017-04-20’, Resource=‘Not Started’),
dict(Task=“Job-3”, Start=‘2017-05-18’, Finish=‘2017-06-18’, Resource=‘Not Started’),
dict(Task=“Job-4”, Start=‘2017-01-14’, Finish=‘2017-03-14’, Resource=‘Complete’)]
Error:
ValueError:
Invalid value of type 'builtins.str' received for the 'annotations' property of layout
Received value: "[{'x': Timestamp('2020-06-01 00:00:00'), 'y': 2, 'text': 'test'}, {'x': Timestamp('2020-07-01 00:00:00'), 'y': 5, 'text': 'test3'}]"
The 'annotations' property is a tuple of instances of
Annotation that may be specified as:
- A list or tuple of instances of plotly.graph_objs.layout.Annotation
- A list or tuple of dicts of string/value properties that
will be passed to the Annotation constructor
Code:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.figure_factory as ff
import plotly.graph_objs as go
# figure
fig = ff.create_gantt(df)
ann = ann.to_dict('records')
ann = str(ann)
# plot figure
fig['layout']['annotations'] = ann
fig.show()