问题描述
我正在尝试将一个“全部”类别添加到datframe的列中,这是我通过这样做实现的。
df2=df1.withcolumn('Column1',lit('all'))
# Union the dataframe
Df_union1=df2.union(df1)
# Adding all to another column
Df_union2=Df_union1.withcolumn('column2',lit('all'))
Df_union_column2=Df_union2.union(Df_union1)
.
.
.
.
.
# grouping the dataframe
Unions_all.groupby(['column1','column2']).....
由于我必须在很多专栏中进行此操作,因为我想将所有排列组合在一起,因此必须有很多并集,我只是想知道是否有更好或更聪明的方法来实现相同的目的
在Json World中,我看到人们做类似的事情
attribute1=['column1','all']
attribute2=['column2','all']
采用attribute1和attribute2的itertools.product
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)