【发布时间】:2020-11-08 10:45:03
【问题描述】:
我有一个看起来像这样的 df:
我正试图把它变成这样:
以下代码为我提供了一个列表列表,我可以将其转换为 df 并包括预期输出的前 3 列,但不确定如何获取我需要的列数(注意:我有超过 3 列列编号,但将此用作简单说明)。
x=[['ID','Start','End','Number1','Number2','Number3']]
for i in range(len(df)):
if not(df.iloc[i-1]['DateSpellIndicator']):
ID= df.iloc[i]['ID']
start = df.iloc[i]['Date']
if not(df.iloc[i]['DateSpellIndicator']):
newrow = [ID, start,df.iloc[i]['Date'],...]
x.append(newrow)
【问题讨论】:
标签: python pandas loops time-series flatten