在我的代码中,我有 12 个 Excel 工作表,其中包含大量行,给我带来问题的那个有 +2k 行,列为(年、周、日期、名称...)
尝试过滤信息,我发现缺少 Excel 实际拥有的信息
groupby_df = df.groupby(['Year','Week','column_a','column_b','column_c','column_d','column_e','column_f']).size().reset_index(name='Amount')
"""
I stoped using the filter because I notice that it didn't have the data of week 44 and year 2024
"""
df['Week'] = df['Week'].astype('int64') #I thought the problem was that the column was a 'UInt32' 32 bits integer so I change it to the one I have used ('int64')
print(df.info()) # Checking if the astype function actually did a change
df_week = df[df['Week']==44]
print(df_week['Year'].unique())
#it print [2023] and it should've also 2024
有人知道问题出在哪里吗?
https://stackoverflow.com/a/38561012/6309278
我假设您的 Excel 文件中有空白,请读取更多数据并使用 dropna(how=all) 删除空白,请参阅上面的链接以获取有关如何读取更多数据的答案。