<!DOCTYPE html>
<html>
<head>
<style>
.container {
background-color: #f9f9f9;
padding: 20px;
margin: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
line-height: 1.5;
}
.code {
background-color: #f5f5f5;
padding: 10px;
border-radius: 5px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Attribute Error - 'series' object has no attribute 'iterrows'</h1>
<p>This error occurs when trying to call the <code>iterrows()</code> method on a Pandas Series object.</p>
<h2>Explanation</h2>
<p>The <code>iterrows()</code> method is a DataFrame method in Pandas, not a Series method. It allows iterating over rows in a DataFrame. However, when called on a Series object, which represents a single column, the method is not available.</p>
<h2>Example</h2>
<div class="code">
<pre><code>import pandas as pd
# Creating a Series object
my_series = pd.Series([1, 2, 3, 4, 5])
# Trying to use iterrows() on a Series
for index, value in my_series.iterrows():
print(index, value)
</code></pre>
</div>
<p>In the example above, we create a Series object called <code>my_series</code> with some values. Then, we try to use the <code>iterrows()</code> method on the Series. However, this results in an Attribute Error since Series objects do not have an <code>iterrows()</code> attribute.</p>
<p>To iterate over values in a Series object, you can use a simple for loop or other applicable methods such as <code>itertuples()</code> or <code>tolist()</code> depending on your specific use case.</p>
</div>
</body>
</html>
Read more interesting post