Home > Mobile >  How to make columns list on pyspark from a other pys[park dataframe
How to make columns list on pyspark from a other pys[park dataframe

Time:07-10

Here's my code

list_selected_apps_id = ['146', '929']
fd_orion_apps = fd_orion_apps.groupBy('msisdn', 'apps_id').pivot('apps_id').count().select('msisdn', *list_selected_apps_id).fillna(0)
fd_orion_apps.show(truncate=False)

I will switch the list_selected_apps_id to all columns from parameter dataframe (200 columns)

Here's the parameter dataframe

DataFrame[_c0: string, 2853: string, 1864: string, 2658: string, 11187: string, 2874: string, 1352: string, 12871: string, 8602: string, 2844: string, 10444: string, 10250: string, 10003: string, 20083: string, 11583: string, 2870: string, 1706: string, 45220: string, 21422: string, 11285: string, 31570: string, 6356: string, 6673: string, 4160: string, 10848: string, 10374: string, 11918: string, 30375: string, 1055: string, 1271: string, 6278: string, 21361: string, 10184: string, 2004: string, 2170: string, 1472: string, 7011: string, 2460: string, 13108: string, 30972: string, 324: string, 12618: string, 13541: string, 2524: string, 14424: string, 6651: string, 10070: string, 10513: string, 31564: string, 392: string, 5405: string, 5167: string, 1884: string, 45243: string, 2312: string, 2115: string, 45027: string, 18: string, 13297: string, 17066: string, 13756: string, 7308: string, 31602: string, 32339: string, 10477: string, 16791: string, 31165: string, 12251: string, 33246: string, 8601: string, 7084: string, 20277: string, 15975: string, 12523: string, 21072: string, 4208: string, 1731: string, 3431: string, 45208: string, 10579: string, 15306: string, 45112: string, 20009: string, 45264: string, 2803: string, 3503: string, 31623: string, 21404: string, 1411: string, 19077: string, 3417: string, 32684: string, 31730: string, 11799: string, 6828: string, 12068: string, 32628: string, 13317: string, 21483: string, 15852: string, 15257: string, 17453: string, 11646: string, 8422: string, 8239: string, 12434: string, 21492: string, 7411: string, 1732: string, 11696: string, 280: string, 30634: string, 12148: string, 45216: string, 10860: string, 21505: string, 11532: string, 10689: string, 32759: string, 45164: string, 10911: string, 31109: string, 12004: string, 11331: string, 3967: string, 10764: string, 272: string, 19635: string, 274: string, 10476: string, 12006: string, 21232: string, 15914: string, 12812: string, 12233: string, 7486: string, 15942: string, 10869: string, 7537: string, 32175: string, 21479: string, 31856: string, 31955: string, 13338: string, 10339: string, 13333: string, 11173: string, 8142: string, 8496: string, 11299: string, 8282: string, 20067: string, 12132: string, 21493: string, 13667: string, 11881: string, 13125: string, 7595: string, 21393: string, 13695: string, 31662: string, 31752: string, 13043: string, 2626: string, 31244: string, 1676: string, 4532: string, 2250: string, 34: string, 31295: string, 12: string, 13550: string, 31728: string, 17747: string, 900: string, 30363: string, 12636: string, 14047: string, 10418: string, 20151: string, 32622: string, 13159: string, 13248: string, 6934: string, 6820: string, 45008: string, 31434: string, 12458: string, 12575: string, 2801: string, 31059: string, 11885: string, 31035: string, 16520: string, 4467: string, 13320: string, 12481: string, 15001: string, 45004: string, 13606: string, 13249: string, 13648: string, 30991: string, 13684: string, 12832: string, 17209: string, 12497: string, 19719: string, 1858: string, 12845: string, 12043: string, 13692: string, 31258: string, 11996: string, 21488: string, 5584: string, 17239: string, 4800: string, 4422: string, 16747: string, 51: string, 12732: string, 11054: string, 13698: string, 2246: string, 10885: string, 11708: string, 3988: string, 20053: string, 8472: string, 6942: string, 45012: string, 30977: string, 11629: string, 10843: string, 12820: string, 15995: string, 15302: string, 10131: string, 33028: string, 32167: string, 7901: string, 6318: string, 1941: string, 10526: string, 1577: string, 13515: string, 16338: string]

I don't want to make list_selected_apps_id manually

CodePudding user response:

Please try

fd_orion_apps = fd_orion_apps.groupBy('msisdn', 'apps_id').pivot('apps_id').count().select('msisdn', *parameter.columns).fillna(0) fd_orion_apps.show(truncate=False)

  • Related