develop a function that Trims leading & trailing white space.
here is a simple sample, but real file contains far more complex rows and columns.
df=pd.DataFrame([["A b ",2,3],[np.nan,2,3],
[" random",43,4],[" any txt is possible "," 2 1",22],
["",23,99],[" help ",23,np.nan]],columns=['A','B','C'])
the result should eliminate all leading & trailing white space, but retain the space inbetween the text.
df=pd.DataFrame([["A b",2,3],[np.nan,2,3],
["random",43,4],["any txt is possible","2 1",22],
["",23,99],["help",23,np.nan]],columns=['A','B','C'])
Mind that the function needs to cover all possible situations.
thank you
See Question&Answers more detail:
os