9 examples of 'drop a column in python' in Python

Every line of 'drop a column in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
97def drop_column(column_name, table, metadata=None):
98 """
99 :param table: Table to drop the column from
100 :type table: :class:`Table` or str
101
102 :param metadata: Needed only if ``table`` is a table name
103 :type metadata: :class:`Metadata`
104 """
105 try:
106 if not isinstance(table, Table):
107 assert metadata is not None
108 table = Table(table, metadata, autoload=True)
109 column = table.c[column_name]
110 column.drop()
111 except Exception:
112 log.exception("Dropping column '%s' from table '%s' failed.", column_name, table)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

47def drop_not_null(self, col):
48 print('Migrating==> [%s] drop_not_null: %s' % (self._name, col))
49 return self.migrator.drop_not_null(self._name, col)
65def delete_column(self, table_name, field_name):
66 sql = "ALTER TABLE %s DROP COLUMN %s CASCADE;" % (
67 self.quote_name(table_name),
68 self.quote_name(field_name)
69 )
70 self.execute(sql)
39def _drop_col(self, df):
40 '''
41 Drops last column, which was added in the parsing procedure due to a
42 trailing white space for each sample in the text file
43 Arguments:
44 df: pandas dataframe
45 Return:
46 df: original df with last column dropped
47 '''
48 return df.drop(df.columns[-1], axis=1)
605def drop_index(self, name, table):
606 return "DROP INDEX %s;" % self.quote(name)
78def drop(table_name, cursor):
79 '''
80 | drop *table_name*
81 '''
82 sql = "DROP TABLE IF EXISTS " + str(table_name)
83 read(sql, cursor)
569def drop_primary_key(self, table_name):
570 """
571 Drops the old primary key.
572 """
573 qn = connection.ops.quote_name
574 self.execute(self.drop_primary_key_string % {
575 "table": qn(table_name),
576 "constraint": qn(table_name+"_pkey"),
2258def visit_drop_index(self, drop):
2259 index = drop.element
2260 return "\nDROP INDEX " + self._prepared_index_name(
2261 index, include_schema=True)
32@generic.copy_column_constraints
33@generic.delete_column_constraints
34def rename_column(self, table_name, old, new):
35 if old == new:
36 # Short-circuit out
37 return []
38 self.execute(
39 "ALTER TABLE %s RENAME COLUMN %s TO %s;"
40 % (self.quote_name(table_name), self.quote_name(old), self.quote_name(new))
41 )

Related snippets