【发布时间】:2019-02-09 02:26:44
【问题描述】:
我正在尝试遍历整个 Python Pandas DataFrame ,但它似乎并没有遍历整个 DataFrame。它适用于长度较短的 DataFrame,但不适用于这个。另外,我在 Jupyter Notebook 工作。
我添加了一些打印语句来尝试调试。
def dropNotIn(df):
print(df.shape)
removedlist = []
droplist = []
for i, x in df.iterrows():
rownum = i
print(rownum)
print(len(df))
dropNotIn(df) 的结果:
(59610, 9)
3449 --> Expected to be 59610
59610
这是我的 df.head():
date attendance venue_city venue_state venue_name away_team home_team away_points home_points
9 2015-12-13 1740.0 Chicago IL McGrath-Phillips Arena Arkansas-Little Rock DePaul 66 44
13 2015-11-22 0.0 St. Thomas NaN Virgin Islands Sport & Fitness Center Tulsa Indiana State 67 59
14 2014-12-04 3469.0 St. Bonaventure NY Reilly Center Buffalo St. Bonaventure 63 72
21 2015-11-20 1522.0 St. Thomas NaN Virgin Islands Sport & Fitness Center Hofstra Florida State 82 77
24 2014-11-23 NaN St. Thomas NaN Virgin Islands Sport & Fitness Center Gardner-Webb Seton Hall 67 85
【问题讨论】:
-
你必须分享一个有代表性的数据样本。
-
@pyeR_biz,已添加。
-
期望 3469,我没有看到您在 DataFrame 的所需输出中提到的其他值。您想要的输出需要匹配哪些条件?
-
@hemanta,我再次编辑了我的问题以排除条件。我想我的问题实际上不需要包含 if 语句。
-
我正在尝试遍历整个 df。每次通过循环,我设置rownum = i,但最后,当我打印rownum时,它与df的大小/长度不匹配。
标签: python pandas loops dataframe for-loop