#pip install pandas
import pandas as pd
df = pd.read_csv("infile.txt", sep=",") # <- change the sep here to match yours
S1, S2 = 2, 1 #columns to skip at the beginning and while concatenating
N, M = 3, 5 #first range of columns to concatenate
(
pd.concat([df.astype(str).iloc[:, i+S1:i+M].agg("".join, axis=1)
for i in range(0, df.shape[1]-M, N+S2)], axis=1)
.pipe(lambda df_: df_.set_axis(df_.columns.map(lambda x: f"Join {x+1}"), axis=1))
.to_csv("outfile.csv", sep=",") # <- change the sep here to match yours
)
1条答案
按热度按时间tv6aics11#
没有pandas标记,但如果您对此持开放态度,这里有一个关于
pandas.concat
的 * 命题 *:输出(* 中间体 *):