Question
Using the Graphviz library and in pandas and jupyternotebook this is the dataset values this is the output required however this is my code but
Using the Graphviz library and in pandas and jupyternotebook this is the dataset values
this is the output required
however this is my code but i am getting error and need help with it
code below
import pandas as pd
from graphviz import Digraph
# Load the data
#df = pd.read_csv("dataframe.csv")
df = pd.read_csv('dataframe.csv', index_col = "ID") # df is "data frame"
#replace all occurances of "Not A Number" (NaN) with "Nothing" (None)
df.replace({float("nan"): None}, inplace=True)
# Create the graph
graph = Digraph(format='jpg')
# Create Nodes for all entries in dataframe
nodeMap = {None:None}
#process your data frame from the bottom up
print("Creating Nodes for Tree")
for index in reversed(df.index.values):
#print("Creating Node for: ",index)
nodeMap[index] = Node(df.loc[index]["Label"],nodeMap[df.loc[index]["Left Child"]],nodeMap[df.loc[index]["Right Child"]]) - NameError: name 'Node' is not defined
ID root Label Right Child Left Child Is it a person not a thing? person thing Real not fictional? washington frodo person washington George Washington Frodo Baggins Bigger than a breadbox? truck A truck A cell phone frodo thing truck cellphone cellphone
Step by Step Solution
3.55 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
The suggested code is as follows In this code several modifications are made and they incl...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started