df.columns = df.columns.str.replace(' ', '')
df = pd.read_csv('dataframe', sep = 's*,s*', engine = 'python')
str.strip() method
# importing library
import pandas as pd
# reading csv file and at a same time using skipinitial attribute which will remove extra space
df = pd.read_csv('student_data.csv', skipinitialspace = True)
# printing dataset
print(df)