The given code is working as expected. Looks like data has some NAN values. Make sure address all the NAN values before converting it to tf.data.Dataset.

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
tf.compat.v1.disable_eager_execution()
#df = pd.read_csv(‘insurance.csv’)
#X = pd.get_dummies(df, columns = [‘sex’, ‘smoker’, ‘region’])
#y = X.pop(‘charges’)
data = {‘sex’:[‘female’, ‘male’, ‘female’, ‘male’],
‘Age’:[‘yes’, ‘no’, ‘no’,‘yes’ ],
‘region’:[‘USA’,‘India’,‘India’,‘USA’]}
data1 = {‘charges’:[100,200,300,400]}
Create DataFrame
X = pd.DataFrame(data)
y = pd.DataFrame(data1)
ds = tf.data.Dataset.from_tensor_slices((X.values, y.values))

Output

<TensorSliceDataset shapes: ((3,), (1,)), types: (tf.string, tf.int64)>