遇到一些错误。如果两个条件都满足,我将尝试过滤掉数据。
import pyodbc
import pandas as pd
import datetime
from dateutil.relativedelta import relativedelta
effdate = datetime.date(2018,12,31)
conn = pyodbc.connect(
r'DRIVER={ODBC Driver 13 for SQL Server};'
r'SERVER=server;'
r'DATABASE=database;'
r'Trusted_Connection=yes;'
)
strSQL = "" # here is a SQL query which pulls many columns, including SaleDate, which is date format, and CategoryName, which contains text
df_auction = pd.read_sql(strSQL, conn)
priordate_rt = effdate + relativedelta(months=-6)
priordate_rt = pd.Timestamp(priordate_rt)
df_auction['SaleDateAdj'] = pd.to_datetime(df_auction['SaleDate'], format='%Y-%m-%d')
df_auction = df_auction[~((df_auction['CategoryName']=='Cars') & (df_auction['SaleDateAdj']<priordate_rt))]
TypeError:“ str”和“ int”的实例之间不支持“ <”
我可以告诉你,这是独立的:
df_test = df_auction[(df_auction['SaleDateAdj']<priordate_rt)]
此行本身给我ValueError:无法从重复的轴重新索引。
df_test = df_auction[(df_auction['CategoryName']=='Cars')]
答案 0 :(得分:1)
尝试做
Properties
然后进行比较以过滤掉。