0

All,

Is it possible to run an rsplit on a whole dataframe without iterating through all columns? I have a CSV file with loads of spaces after most of the fields (Not column specific).

Any help is much appreciated.

Edit: the csv would look like the following and I would like to remove all the spaces on the right of each field (at the time of read_csv would be the best):

"JoeK    ","Joe     ","Kavanagh   ","joe.kavanagh@nomail.com  "
"BarryD  ","Barry","Dempsy     ","bdempsy@nomail.com"
"OrlaF","Orla    ","Farrel     ","ofjk@nomail.com             " 
"SethB   ","Seth    ","Black      ","sblack@nomail.com         "
"KateW   ","Kate    ","White      ","kw12@nomail.com              "
Riki Lyng
  • 317
  • 4
  • 19
  • What did you try? Attach part of your dataframe. You could use `apply` with `rsplit`. – Anton Protopopov Dec 08 '15 at 08:26
  • You could also remove all the white spaces while reading the CSV in the dataframe. – Mel Dec 08 '15 at 08:51
  • Possible duplicate of [How to make separator in read\_csv more flexible wrt whitespace?](http://stackoverflow.com/questions/15026698/how-to-make-separator-in-read-csv-more-flexible-wrt-whitespace) – Mel Dec 08 '15 at 08:52

1 Answers1

0

If you can split the reading from the removal of whitespace:

df = pd.read_csv('mycsv.csv')
df_nowhitespace = df.applymap(str.strip)
jmz
  • 4,138
  • 28
  • 27