Answered by : annoying-alligator-gmkysmitqk2f
df.columns = df.columns.str.replace(' ', '')
Source : https://stackoverflow.com/questions/41476150/removing-space-from-dataframe-columns-in-pandas | Last Update : Thu, 31 Dec 20
Answered by : hilarious-herring-75uj9gyi9rfn
df.columns = df.columns.str.strip()
Source : https://stackoverflow.com/questions/41476150/removing-space-from-columns-in-pandas/41476181#41476181 | Last Update : Wed, 11 Aug 21
Answered by : anxious-alligator-61ke0kgw6vaj
df_obj = df.select_dtypes(['object'])
print (df_obj)
0 a
1 c
df[df_obj.columns] = df_obj.apply(lambda x: x.str.strip())
print (df) 0 1
0 a 10
1 c 5
Source : https://stackoverflow.com/questions/40950310/strip-trim-all-strings-of-a-dataframe | Last Update : Wed, 08 Jun 22
Answered by : hilarious-herring-75uj9gyi9rfn
df.columns = df.columns.str.rstrip()
Source : https://stackoverflow.com/questions/41476150/removing-space-from-columns-in-pandas/41476181#41476181 | Last Update : Wed, 11 Aug 21
Answered by : hilarious-herring-75uj9gyi9rfn
df.columns = df.columns.str.lstrip()
Source : https://stackoverflow.com/questions/41476150/removing-space-from-columns-in-pandas/41476181#41476181 | Last Update : Wed, 11 Aug 21
Answered by : breakable-buffalo-bfq0iwk309ot
' hello world! '.strip()
'hello world!'
' hello world! '.lstrip()
'hello world! '
' hello world! '.rstrip()
' hello world!'
Source : https://www.tutorialspoint.com/How-to-remove-all-leading-whitespace-in-string-in-Python | Last Update : Tue, 01 Dec 20
Answered by : itchy-iguana-yewbikurcqns
# 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)
Source : https://www.geeksforgeeks.org/pandas-strip-whitespace-from-entire-dataframe/ | Last Update : Tue, 12 Jul 22
Answered by : rudythealchemist
str.strip() method
Source : https://app.dataquest.io/c/54/m/293/data-cleaning-basics/2/cleaning-column-names | Last Update : Sun, 01 Aug 21
Answered by : kwams-ahortor
df = pd.read_csv('dataframe', sep = '\s*,\s*', engine = 'python')
Source : | Last Update : Sun, 06 Jun 21