Answers for "drop columns delta table"

0

drop columns delta table

schema='<schema>'
table='<table>'

columnstoDrop = ["<column or columns to drop>"]
display(spark.sql(f"describe table {schema}.{table}"))
df = spark.sql(f"Select * from {schema}.{table}")

df1 = df.drop(*columnstoDrop)

spark.sql(f"DROP TABLE if exists {schema}.{table}")

df1.write \
  .format(write_format) \
  .mode('overwrite') \
  .option("overwriteSchema", "true") \
  .save(f"{save_path}{table}")

spark.sql(f"CREATE  TABLE  {schema}.{table}  USING DELTA LOCATION '{save_path}{table}'")

display(spark.sql(f"describe table {schema}.{table}"))
Posted by: Guest on April-19-2022
0

drop column of datfame

df.drop(['B', 'C'], axis=1)
Posted by: Guest on April-18-2022

Python Answers by Framework

Browse Popular Code Answers by Language