what is the error? 07-26T13:50:57.768630+00:00 [2023-07-26, 16:52:57 MSK] {base.py:73}…
- User
what is the error? 07-26T13:50:57.768630+00:00 [2023-07-26, 16:52:57 MSK] {base.py:73} INFO - Using connection ID 'markout' for task execution. [2023-07-26, 16:55:29 MSK] {taskinstance.py:1776} ERROR - Task failed with exception Traceback (most recent call last): File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1901, in _execute_context cursor, statement, parameters, context File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute cursor.execute(statement, parameters) psycopg2.errors.NotNullViolation: null value in column "Дата события" of relation "csv_import_events" violates not-null constraint DETAIL: Failing row contains (null, ;";";";";";";";";";";";";";";";2023.06.29 14:18:38", 3, , , , , , , null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 11221, 2023-07-26T15:52:06.790729000, null).
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/airflow/.local/lib/python3.7/site-packages/airflow/operators/python.py", line 175, in execute return_value = self.execute_callable() File "/home/airflow/.local/lib/python3.7/site-packages/airflow/operators/python.py", line 192, in execute_callable return self.python_callable(*self.op_args, **self.op_kwargs) File "/opt/airflow/dags/csv_import_main.py", line 141, in write_data_to_database cm._psql_upsert(df, 'csv_import_events', 'staging', db = 'markout') File "/opt/airflow/dags/common.py", line 206, in _psql_upsert conn.execute(upsert_statement) File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1380, in execute return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS) File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 335, in _execute_on_connection self, multiparams, params, execution_options File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1582, in _execute_clauseelement cache_hit=cache_hit, File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1944, in execute_context e, statement, parameters, cursor, context File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2125, in handle_dbapi_exception sqlalchemy_exception, with_traceback=exc_info[2], from=e File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 211, in raise raise exception File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1901, in _execute_context cursor, statement, parameters, context File "/home/airflow/.local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "Дата события" of relation "csv_import_events" violates not-null constraint DETAIL: Failing row contains (null, ;";";";";";";";";";";";";";";";2023.06.29 14:18:38", 3, , , , , , , null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 11221, 2023-07-26T15:52:06.790729000, null).
- Assistant
The error in the above code is a
NotNullViolation. It occurs when anullvalue is being inserted into the "Дата события" (Date of Event) column of the "csv_import_events" table, but this column has a not-null constraint. The failing row contains anullvalue in this column along with other values. - User
how to dalete null values from dataframe python?
- Assistant
To delete null values from a dataframe in Python, you can use the
dropna()method. Here's an example:pythonimport pandas as pd # Create a dataframe with null values data = {'A': [1, 2, None, 4, 5], 'B': [None, 6, 7, 8, None]} df = pd.DataFrame(data) # Delete rows with null values df = df.dropna() print(df)Output:
codeA B 1 2.0 6.0In the above example, the
dropna()method is called on the dataframedfto drop any row that contains null values. The resulting dataframedfwill only contain the rows without null values.