1 回答
TA贡献1844条经验 获得超8个赞
我假设您的列已经按 id、阶段和版本的顺序排列。索引 3 之后也没有数字ID:
# read excel
df = pd.read_excel('pver.xlsx')
# find the columns that start with ID, transpose, reset the index and split on colon
ids = df[df.columns[df.columns.str.startswith('ID')]].T.reset_index()['index'].str.split(':.|:', expand=True)[1].to_numpy()
# find the columns that start with QA and transpose
phase = df[df.columns[df.columns.str.startswith('QA')]].T[0].to_numpy()
# find the columns that start with V or OEM, and transpose
v = df[df.columns[df.columns.str.startswith('V') | df.columns.str.startswith('OEM SW')]].T.index
# vstack and to pd.dataFrame
new_df = pd.DataFrame(np.vstack([ids,v,phase])).T
# name columns
new_df.columns = ['ID', 'Version', 'Phase']
ID Version Phase
0 1907839 V100 during development
1 01907820 V110 during development
2 189634226 V120 during development
3 V130 during development
4 1 V200 Raw Container
5 2 V220 NaN
6 3 OEM SW name NaN
7 4 OEM SW name.1 NaN
8 5 OEM SW name.2 NaN
9 6 OEM SW name.3 NaN
10 7 OEM SW name.4 NaN
11 8 OEM SW name.5 NaN
12 9 OEM SW name.6 NaN
13 10 OEM SW name.7 NaN
14 11 OEM SW name.8 NaN
15 12 OEM SW name.9 NaN
添加回答
举报