【发布时间】:2016-08-25 00:08:24
【问题描述】:
我想在加载到 excel 文件中的 for 循环中删除最终文件中的 NaN 行,并删除所有公司、电子邮件、创建的重复列,但最终加载到 excel 文件中。
这是我的 for 循环(以及随后合并到单个 DF),目前:
for f in glob.glob("./gowall-users-export-*.xlsx"):
df = pd.read_excel(f)
all_users_sheets_hosts.append(df)
j = re.search('(\d+)', f)
df.columns = df.columns.str.replace('.*Hosted Meetings.*', 'Hosted Meetings' + ' ' + j.group(1))
all_users_sheets_hosts = reduce(lambda left,right: pd.merge(left,right,on=['First Name', 'Last Name'], how='outer'), all_users_sheets_hosts)
这是生成的 DF 的前几行:
Company_x First Name Last Name Emails_x Created_x Hosted Meetings 03112016 Facilitated Meetings_x Attended Meetings_x Company_y Emails_y ... Created_x Hosted Meetings 04122016 Facilitated Meetings_x Attended Meetings_x Company_y Emails_y Created_y Hosted Meetings 04212016 Facilitated Meetings_y Attended Meetings_y
0 TS X Y X@Y.com 03/10/2016 0.0 0.0 0.0 TS X@Y.com ... 03/10/2016 0.0 0.0 2.0 NaN NaN NaN NaN NaN NaN
1 TS X Y X@Y.com 03/10/2016 0.0 0.0 0.0 TS X@Y.com ... 01/25/2016 0.0 0.0 0.0 NaN NaN NaN NaN NaN NaN
2 TS X Y X@Y.com 03/10/2016 0.0 0.0 0.0 TS X@Y.com ... 04/06/2015 9.0 10.0 17.0 NaN NaN NaN NaN NaN NaN
【问题讨论】:
-
什么是 NaN 行? any 值是 NaN 的行吗?或 all 值为 NaN 的行?还是...?
-
在这种情况下,具有任何 NaN 值的行将具有所有 NaN 值,因此没有区别。不过,我应该提到这一点。