是否有针对包含多个字符串的大型 .CSV 列的时间拆分函数?
Is there any time-wise split function to a large .CSV column contains multiple strings?
我有 CSV 文件,我需要按 char = '|||' 拆分 特定列的字符串
所以当我使用迭代方式时 它有效 但需要 太多时间 到 运行:
for i in range(dataset.shape[0]): #### 9000 Rows
col = dataset.iloc[i, 1].split('|||')
您还有其他时间上的解决方案吗?
Dataset example
我需要拆分帖子栏
您可以尝试使用 NumPy 的 loadtxt or genfromtxt 函数加载 CSV 文件。 NumPy 将比 for 循环快得多。
例如,
import numpy as np
data = np.genfromtxt("myfile.csv", delimiter="|||")
# Example to access column number 27
data[:, 27]
编辑
如果您希望通过特定的分隔符拆分字符串数组,您可以尝试使用 np.char.split.
示例
split_columns = np.char.split(dataset[:, 1], sep=',')
我有 CSV 文件,我需要按 char = '|||' 拆分 特定列的字符串 所以当我使用迭代方式时 它有效 但需要 太多时间 到 运行:
for i in range(dataset.shape[0]): #### 9000 Rows
col = dataset.iloc[i, 1].split('|||')
您还有其他时间上的解决方案吗? Dataset example
我需要拆分帖子栏
您可以尝试使用 NumPy 的 loadtxt or genfromtxt 函数加载 CSV 文件。 NumPy 将比 for 循环快得多。
例如,
import numpy as np
data = np.genfromtxt("myfile.csv", delimiter="|||")
# Example to access column number 27
data[:, 27]
编辑
如果您希望通过特定的分隔符拆分字符串数组,您可以尝试使用 np.char.split.
示例
split_columns = np.char.split(dataset[:, 1], sep=',')