Creating categories while importing via CSV

I was able to solve this by checking if the term exists, and then using tax_input in wp_insert_post()

// Check if the category exists
$category_term = term_exists(trim($category), 'formula_types', 0);

// Create category if it doesn't exist
if (!$category_term) {
    $category_term = wp_insert_term(trim($category), 'formula_types', array('parent' => 0));
}
array_push($formattedCategories, (int)$category_term['term_taxonomy_id']);

$post = array(
    'post_title'    => $results['drug_name'],
    'post_type'     => 'formula',
    'post_status'   => 'publish',
    'tax_input'    => array(
            'formula_types' =>
            $formattedCategories,
    )
);