Pandasql:Python int 太大,无法转换为 SQLite INTEGER

Pandasql: Python int too large to convert to SQLite INTEGER

我在 运行 我的代码中遇到以下 'Python int too large to convert to SQLite INTEGER' 错误。我是 psql 的初学者。

代码:

import pandas as pd
import numpy  as np
import pandasql as psql
from pandasql import sqldf

T900_file = r'K:\myfile.xlsx'
df1 = pd.read_excel(T900_file)

T1000 = psql.sqldf("""Select Date
                            ,UP_Cust_Num
                            ,UP_Cust_Name
                            ,sum(Utilized_FVO)  as FVO
                            ,avg(UP_Generation) as UP_Gen
                      from df1
                      Group by Date, UP_Cust_Num, UP_Cust_Name""")

错误必须与聚合有关。我该如何解决错误?任何帮助将不胜感激。

我认为这意味着你有一个溢出错误,所以它打破了一个int的边界。

这似乎是 df1 中数据类型的问题。如果你运行

df1.info()

您可能会看到一些数值类型为 Int64;如果是这种情况,那么您可以将这些值转换为较小的整数(提供适合新数据类型的值)。为了转换为更小的整数,您可能需要这样做:

df1["Utilized_FVO"] = df["Utilized_FVO"].astype(np.int8)
df1["UP_Generation"] = df["UP_Generation"].astype(np.int8)