将熊猫数据框字符串拆分为多个空格

时间:2019-03-01 16:40:21

标签: python regex pandas split

我到处搜索并找到re.split以查找正常的字符串,但无法在df中使用它

这是与类似问题的不同之处-我需要语法将我的解决方案一次应用于整个列,而不仅仅是一个字符串

我以前使用过

# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

# base-files version 4.2-4

# ~/.profile: executed by the command interpreter for login shells.

# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.profile

# Modifying /etc/skel/.profile directly will prevent
# setup from updating it.

# The copy in your home directory (~/.profile) is yours, please
# feel free to customise it to create a shell
# environment to your liking.  If you feel a change
# would be benificial to all, please feel free to send
# a patch to the cygwin mailing list.

# User dependent .profile file

# Set user-defined locale
export LANG=$(locale -uU)

# This file is not read by bash(1) if ~/.bash_profile or ~/.bash_login
# exists.
#
# if running bash
if [ -n "${BASH_VERSION}" ]; then
  if [ -f "${HOME}/.bashrc" ]; then
    source "${HOME}/.bashrc"
  fi
fi

但是有时候我有4或5个空格很好,而其他时候我有10个空格,所以我得到空列

我需要定义4个或更多空格并在熊猫中工作的东西

任何帮助,不胜感激!

2 个答案:

答案 0 :(得分:2)

尝试此正则表达式

(\s{4,})

的空白 {4,}至少4次

答案 1 :(得分:1)

您可以尝试以下方法:

keeptemp = myalerts['Temp'].str.split(" +",expand = True)

“ +”表示一个或多个空格