Last active
February 22, 2023 23:35
-
-
Save yvan/a28ba9b15668225fd94534c05f97cdbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pandas | |
df[col4] = df[col4].apply(lambda m: None if m in [None, float('nan'), np.nan, math.nan] else int(float(m))) | |
# pyspark | |
def floatint(x): | |
return int(float(x)) | |
int_udf = F.udf(lambda m: None if m is None else floatint(m)) | |
df = df.withColumn(col4, F.when(F.col(col4).isNotNull(), int_udf(F.col(col4))).otherwise(None)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment