You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get the error Invalid column name 'nan' when passing a DataFrme with nans to a SQLAlchemy table that allows nans. I've tried passing a na_values with a sqlalchemy null but it doesn't seem to be recognizing the replace.
From the error it seems like it is passing literally nan into the SQL INSERT statements.
Code as below:
# Upload to Server
import sqlalchemy as sa
from odo import odo
tmps = pd.read_csv(EPS_FILE)
tmps['DT'] = pd.to_datetime(fdata['Period (YYYYMMDD)'], format='%Y%m%d')
tmps['Ticker'] = fdata['Ticker'].str.split('-').str[0]
tmps['YYYY'] = tmps['DT'].dt.year
tmps['MM'] = tmps['DT'].dt.month
tmps['DD'] = tmps['DT'].dt.month
rnamecol = {
'NI-LYEAR': 'LYEAR_MED',
'NI-LYEAR_MEAN': 'LYEAR_MEAN',
'NI-CYEAR': 'CYEAR_MED',
'NI-CYEAR_MEAN': 'CYEAR_MEAN',
'NI-NYEAR': 'NYEAR_MED',
'NI-NYEAR_MEAN': 'NYEAR_MEAN',
'NI-Current_Annual_Stated': 'CURR_ANN',
'NI-Current_LTM_Sem': 'CURR_LTMSA',
'NI-Current_LTM_Q': 'CURR_LTMQ',
'NI-Revise Up': 'ReviseUp',
'NI-Revise Down': 'ReviseDown',
'NI-NEST': 'NEST'
}
tmps.rename(columns=rnamecol, inplace=True)
md = sa.MetaData(bind='mssql+pymssql://w:[email protected]/UserDB')
tbl = sa.Table('tmp_FS_NetIncome', md,
sa.Column('YYYY', sa.Integer, nullable=False),
sa.Column('MM', sa.Integer, nullable=False),
sa.Column('DD', sa.Integer, nullable=False),
sa.Column('DT', sa.DATE, nullable=False),
sa.Column('Ticker', sa.String(6), nullable=False),
sa.Column('CURR_ANN', sa.Float),
sa.Column('CURR_LTMSA', sa.Float),
sa.Column('CURR_LTMQ', sa.Float),
sa.Column('LYEAR_MED', sa.Float),
sa.Column('LYEAR_MEAN', sa.Float),
sa.Column('CYEAR_MED', sa.Float),
sa.Column('CYEAR_MEAN', sa.Float),
sa.Column('NYEAR_MED', sa.Float),
sa.Column('NYEAR_MEAN', sa.Float),
sa.Column('ReviseUp', sa.Integer),
sa.Column('ReviseDown', sa.Integer),
sa.Column('NEST', sa.Integer)
)
tmps = tmps.loc[:, [l.name for l in tbl.columns]]
notnum = set([
'Ticker', 'DT'
])
tmps['Ticker'] = tmps['Ticker'].astype('str')
tmps['DT'] = pd.to_datetime(tmps['DT'])
for cc in tmps.columns:
if not cc in notnum:
tmps[cc] = pd.to_numeric(tmps[cc])
t = odo(
tmps, tbl, na_values='NULL' # Also tried na_values=sa.null() or na_values=''
)
I get the error
Invalid column name 'nan'
when passing a DataFrme with nans to a SQLAlchemy table that allows nans. I've tried passing a na_values with a sqlalchemy null but it doesn't seem to be recognizing the replace.From the error it seems like it is passing literally
nan
into theSQL INSERT
statements.Code as below:
And error (truncated) below:
The text was updated successfully, but these errors were encountered: