【发布时间】:2021-11-18 11:48:50
【问题描述】:
以下是我在 SQL Server 中的数据
在python中读取数据后变成这样
我使用下面的代码将值拆分为多列
# 1. To split single array column to multiple column based on '\t'
df[['v1','v2','v3','v4','v5','v6','v7','v8','v9','v10','v11','v12','v13','v14','v15',\
'v16','v17','v18','v19','v20','v21','v22','v23','v24','v25','v26','v27','v28',\
'v29','v30','v31','v32','v33','v34','v35','v36','v37','v38','v39','v40','v41']] = df['_VALUE'].str.split(pat="\t", expand=True)
# 2. To remove the '\r\n' from the last column
df['v41'] = df['v41'].replace(r'\s+|\\n', ' ', regex=True)
但在某些数据集中,数组值更多,例如。 100列,上面的代码这么大。我必须从 V1 写到 V100。有什么简单的方法可以做到这一点。
【问题讨论】: