数组python split str(太多值无法解包)

2024-10-02 00:43:19 发布

您现在位置:Python中文网/ 问答频道 /正文

数组python split str(太多值无法解包)

df.timestamp[1]
Out[191]:
'2016-01-01 00:02:16' 
#i need to slept these into to feature 
split1,split2=df.timestamp.str.split(' ')

Out[192]:
ValueErrorTraceback (most recent call last)
<ipython-input-216-bbe8e968766f> in <module>()
----> 1 split1,split2=df.timestamp.str.split(' ')

ValueError: too many values to unpack

Tags: todf数组needouttimestampfeaturesplit
2条回答

使用str[index]因为您要拆分序列,输出也将是一个序列,而不是pandas中的两个不同列表。在

df = pd.DataFrame({'timestamp':['2016-01-01 00:02:16','2016-01-01 00:02:16'] })

split1,split2  = df.timestamp.str.split(' ')[0], df.timestamp.str.split(' ')[1]

例如,str.split将返回一个序列

^{pr2}$

您错误地使用了split()方法。在

鉴于此:

df.timestamp[1]
Out[191]:
'2016-01-01 00:02:16'

像这样使用split()方法:

^{pr2}$

相关问题 更多 >

    热门问题