分列熊猫

I have a problem, I'm trying to split this column from a pandas dataframe in to two seperate columns 'Date' and 'Names'.

评论
  • Guy
    Guy 回复

    If the dates are always 10 characters long, use the str accessor:

    df['Date'], df['Names'] =  df['col'].str[:10], df['col'].str[10:]
    
                            col        Date           Names
    0  2020-02-15Kennedy-Harris  2020-02-15  Kennedy-Harris
    1     2020-01-28Sanders LLC  2020-01-28     Sanders LLC
    
  • uqui
    uqui 回复

    看来您的日期格式是相当静态的。 “ 2020-01-01FirstName,LastName”。不清楚您使用的是哪种语言,但是您可以很容易地将前10个字符抓成一个字符,然后将其余字符抓成第2个字符。