Skip to content Skip to sidebar Skip to footer

Attributeerror: 'series' Object Has No Attribute 'iterrows'

accounts = pd.read_csv('C:/*******/New_export.txt', sep=',', dtype={'number': object}) accounts.columns = ['Number', 'F'] for i, j in accounts['Number'].iterrows(): #i represents

Solution 1:

accounts["Number"] is a Series object, not a DataFrame. Either iterate over accounts.iterrows() and take the Number column from each row, or use the Series.iteritems() method.

Iterating over the dataframe:

for i, rowin accounts.iterrows():
    if str(row['Number']) == "27*******5":
        print(row["F"], row["Number"])

or over Series.iteritems():

for i, number in accounts['Number'].iteritems():
    if str(number) == "27*******5":
        print(accounts["F"][i], number)

Post a Comment for "Attributeerror: 'series' Object Has No Attribute 'iterrows'"