Syanpse code is not dropping the columns from the array list replaceCols from a Dataframe

21 Views Asked by At

replaceCols=[ "LEI", "Entity_LegalName", "Entity_LegalAddress_FirstAddressLine", "Entity_LegalAddress_City", "Entity_LegalAddress_Country", "Entity_HeadquartersAddress_FirstAddressLine", "Entity_HeadquartersAddress_City", "Entity_HeadquartersAddress_Country", "Entity_RegistrationAuthority_RegistrationAuthorityID", "Entity_LegalJurisdiction", "Entity_LegalForm_EntityLegalFormCode", "Entity_EntityStatus", "Registration_InitialRegistrationDate", "Registration_LastUpdateDate", "Registration_RegistrationStatus", "Registration_NextRenewalDate", "Registration_ManagingLOU", "Registration_ValidationSources" ]

Dataframe df has the above column plus many others after reading a csv source file.

df_W = df.drop(str(col(c).alias(c) for c in replaceCols))

The code is syntactically correct but is unable to drop the Dataframe columns mentioned in the ArrayList replaceCols.

1

There are 1 best solutions below

1
Wasim Syed On

Solution:

df_W = df.drop(*replaceCols)