The following error occurs when inserting in postgresql. Somebody help me

import numpy as np
import psycopg2
import pandas.io.sql as pd_sql
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import rc

conn = psycopg2.connect(host=‘XXX.XXX.XXX.XXX’, dbname=‘XXXX’, user=‘XXXX’, password=‘XXXX’, port=‘5432’) #
cur = conn.cursor()

anomalyquery = “select to_char(mdate,‘YYYY-MM-DD’) as date ,case when sum(use_value)=‘0’ then 0 else 1 end as status from tbl_water_meter_dummy group by date order by date asc”
cur.execute(anomalyquery, conn)
anomaly = pd_sql.read_sql(anomalyquery, conn)

conn.commit()
anomaly.head(365)

20200610_164823

anomaly[‘date’] = pd.to_datetime(anomaly[‘date’], errors=‘raise’)
anomaly.dtypes

try:
connection = psycopg2.connect(user=“XXXX”,
password=“XXXX”,
host=“XXX.XXX.XXX.XXX”,
port=“5432”,
database=“XXXX”)
cursor = connection.cursor()

postgres_insert_query = “”" INSERT INTO tbl_emergency (date, status) VALUES (%s, %s)"""
record_to_insert = (anomaly[‘date’],anomaly[‘status’])
cursor.execute(postgres_insert_query, record_to_insert)

connection.commit()
count = cursor.rowcount
print (count, “Record inserted successfully into mobile table”)

except (Exception, psycopg2.Error) as error :
if(connection):
print(“Failed to insert record into mobile table”, error)

finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print(“PostgreSQL connection is closed”)

this error… I have a problem like this

Failed to insert record into mobile table can’t adapt type 'Series’
PostgreSQL connection is closed

The SQL ‘Insert’ statement does not work with multiple rows: it is strictly one row at a time. You are passing your DataFrame object (anomaly) as the value for your insert query. You must iterate across the DataFrame row-by-row, and pass each row’s date/status values as a separate insert query.