我有以下代码,旨在从 1 个数据帧创建 2 个单独的表。这些表应用了不同的过滤器。我发现,一旦应用第一个过滤器,原始数据框就会“改变”。df_orig = pd.read_excel('JRMaster.xlsm')df_orig.columns = map(str.upper, df_orig.columns)df_orig['SYSTEM'] = df_orig['SYSTEM'].str.upper()df_orig['STATUS'] = df_orig['STATUS'].str.upper()df = df_orig.copy(deep=True)df_copy_all = df_orig.copy(deep=True)df = df[(df['DATE PAID'].dt.month.between(10,10)) & (df['DATE PAID'].dt.year == 2020)]df2 = df_copy_all[(df_copy_all['DATE SENT'].dt.month.between(10,10)) & (df['DATE SENT'].dt.year == 2020)]df 和 df2 应该有两个不同的结果,但输出是相同的。我尝试过 df.copy() 和 df.copy(deep=True)使用 Pandas 1.0.5 和 Python 3.6一些论坛指出这是一个错误,但我想检查是否有解决方法或修复此问题。我想到的另一种方法是将原始 Excel 文档读入多个数据帧,但这似乎不可持续且资源繁重。编辑:示例数据如下:System DATE SENT STATUS DATE PAID0 One 2020-10-01 OPEN NaT1 One 2020-10-01 OPEN NaT2 THREE 2020-10-01 SR 2020-10-073 One 2020-10-01 DUP NaT4 One 2020-10-01 OPEN NaT5 One 2020-10-01 OPEN NaT6 THREE 2020-10-01 OPEN NaT7 One 2020-10-01 DUP NaT8 THREE 2020-10-01 AR 2020-07-319 THREE 2020-10-01 OPEN NaT10 One 2020-10-01 AR 2020-08-2111 One 2020-10-01 DUP NaT12 One 2020-10-01 OPEN NaT13 One 2020-10-01 DUP NaT14 One 2020-10-01 DUP NaT15 One 2020-10-01 DUP NaT16 One 2020-10-01 DUP NaT17 THREE 2020-10-01 OPEN NaT18 One 2020-10-01 OPEN NaT19 One 2020-10-01 OPEN NaT
2 回答
慕森卡
TA贡献1806条经验 获得超8个赞
问题实际上是一个拼写错误:
df2 = df_copy_all[(df_copy_all['DATE SENT'].dt.month.between(10,10)) & (df['DATE SENT'].dt.year == 2020)]
应该
df2 = df_copy_all[(df_copy_all['DATE SENT'].dt.month.between(10,10)) & (df2['DATE SENT'].dt.year == 2020)]
错误位于:df2['DATE SENT'],我有 df['DATE SENT']
添加回答
举报
0/150
提交
取消