Need help changing shader to group

Is there a way to change the diffuse shader to an existing group through python?

Here is what I’ve got so far, I’ve tried everything to make it work.
I already have the group appended from another blend file. I just want to assign it by replacing the default shader(Diffuse) to the existing group.

import bpy

# Add material and toggle use nodes.
material ="Material")
material.use_nodes = True

# Remove default diffuse shader
material.node_tree.nodes.remove(material.node_tree.nodes.get('Diffuse BSDF'))

# Adding the group doesnt seem to work, must be because active area.type is not "NodeEditor"?
#Any way of making this work?
bpy.ops.node.add_node(type="ShaderNodeGroup", settings=[{"name":"node_tree", "value":"['carpaint_group']"}], use_transform=True)

# Get material output
material_output = material.node_tree.nodes.get('Material Output')
# Get group 
group = material.node_tree.nodes.get('carpaint_group')

#link material output to group[0], group.outputs[0])

# set active material to your new material
bpy.context.object.active_material = material

This is how I would do it:

import bpy


mat.node_tree.nodes.remove(mat.node_tree.nodes['Diffuse BSDF'])'ShaderNodeGroup')['carpaint_group'][0], mat.node_tree.nodes['Material Output'].inputs['Surface'])

Awesome. Thanks!