pd.DataFrame.itertuples
returns an iterable of namedtuples including the index by default.
There are two options to account for this.
Option 1
Unpack 3 items instead of 2, the first of which you do not use.
Here is a minimal example:
df = pd.DataFrame([[10, 20], [30, 40], [50, 60]],
columns=['A', 'B'])
for idx, a, b in df.itertuples():
print(idx, a, b)
0 10 20
1 30 40
2 50 60
In your case, a good convention to use would be to indicate an unused variable by _
:
for _, file_date, file_name in process_list[['date', 'name']].itertuples():
# do something
Option 2
Use index=False
argument and unpack 2 elements:
for file_date, file_name in process_list[['date', 'name']].itertuples(index=False):
# do something
The behaviour is indicated in the documentation:
DataFrame.itertuples(index=True, name='Pandas')
Iterate over DataFrame rows as namedtuples, with index value as first
element of the tuple.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…