如何根据 Big Query 中列中的值生成 n 行?

how to generate n rows based on a value in a column in Big Query?

我关注table。

我需要转换此输入,如下面的输出示例所示:

如果您有任何想法,请分享。非常感谢!

使用 Index.repeat for new rows by DataFrame.loc,删除 no 列,获取 flag 列并最后创建默认 RangeIndex:

df1 = (df.loc[df.index.repeat(df['no'])]
         .drop('no', axis=1)
         .assign(flag=1)
         .reset_index(drop=True))
print (df1)
   id_1  id_2  flag
0     A   100     1
1     A   100     1
2     A   100     1
3     A   200     1
4     A   301     1
5     A   301     1
6     B   122     1
7     B   122     1
8     B   122     1
9     B   122     1
10    B   100     1