熊猫:整个数据帧上的rsplit

时间:2015-12-08 08:25:30

标签: python python-2.7 pandas

所有

是否可以在整个数据帧上运行rsplit而无需迭代所有列?我有一个CSV文件,在大多数字段后面都有大量空格(非特定于列)。

非常感谢任何帮助。

编辑: csv看起来如下所示,我想删除每个字段右边的所有空格(在read_csv时最好):

"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              "

1 个答案:

答案 0 :(得分:0)

如果你可以从删除空格中拆分读数:

df = pd.read_csv('mycsv.csv')
df_nowhitespace = df.applymap(str.strip)