Python 熊猫:删除索引值并在Excel中将一个单元格中的值拆分为不同的行

Python 熊猫:删除索引值并在Excel中将一个单元格中的值拆分为不同的行,python,pandas,Python,Pandas,我编写这段代码是为了从一个excel文件中提取数据,然后再次准备另一个excel文件,其中包含提取的ID、版本和阶段。它将其提取出来,但将其错误地放在excel中。它将值与索引一起放置,并将所有ID放在excel中一个单元格中所有版本放在一个单元格中,因此我希望它位于ID列下方的不同行中 这是我的密码 [输入文件链接]()[输出文件链接]() 这段代码正在查找我需要的数据,但输出错误 excel中的输出为 id version

我编写这段代码是为了从一个excel文件中提取数据,然后再次准备另一个excel文件,其中包含提取的ID、版本和阶段。它将其提取出来,但将其错误地放在excel中。它将值与索引一起放置,并将所有ID放在excel中一个单元格中所有版本放在一个单元格中,因此我希望它位于ID列下方的不同行中
这是我的密码 [输入文件链接]()[输出文件链接]()

这段代码正在查找我需要的数据,但输出错误

excel中的输出为

   id                  version                     required  
0  17 X 18 Y 22 Z     20 1  21 2 24 3            18 gantt 19 Pie 23 ipex
但是我希望它是这样的,而不是将索引拆分为不同的行,而不是全部拆分为一个单元格。

  id      version     required
0 X        1           gantt
1 Y        2           Pie
2 Z        3           ipex

有人能帮我一下吗?

我假设你的专栏已经按照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

只需将index=False添加到to_excel函数中,即可摆脱index=False,但它仍然会给出带有索引值的输出。我想在我试图提取数据的步骤中,列表中嵌入了索引值,我不知道是否应该将index=False放在那里。我可以在mylist中的某个地方删除索引吗?代码中有很多问题,您可以添加示例输入和输出,然后我们可以帮助您Hi DataNoyer在这里重新链接到数据感谢[input File Link]()[output File Link]()哇!我完全惊讶于代码的简单程度。非常感谢,这会有很大帮助的。
# 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