The following error message occurred while implementing a function that extracts data that meets certain conditions from a csv file using pandas and displays the value of the extracted data.
Since the value of n is larger than the number of extracted data, I think it is an error that occurs, but I would like to know the solution.
IndexError: single positional indexer is outofbounds
Corresponding source code
import pandas as pd
import sys
n = 0
shain_data = pd.read_csv ("/content/shainlist.csv",
encoding = "utf8",
names = ('code','shimei','furigana','section','flag','nyusha_date','taisha_date'))
search_name = input ("Enter the name I want to search for in Kanji.") #Conditions I want to search
result = shain_data [shain_data ['shimei']. str.contains (search_name)] # Extract by condition
result_shimei = result ['shimei']
for i in result:
result_shimei = result ['shimei']
result_shimei_only = result_shimei.iloc [n]
n = n + 1
print (result_shimei_only)
What I tried
I tried to count the number of extracted data and turn the for statement, but I couldn't do it.
The value of result_shimei.
1 Chiharu Yamamura
5 Terumi Takayama
7 Misa Oyamada
35 Shinkichi Koyama
Name: shimei, dtype: object
IndexError Traceback (most recent call last)
2 for i in result:
3 result_shimei = result ['shimei']
>4 result_shimei_only = result_shimei.iloc [n]
5 n = n + 1
6 print (result_shimei_only)
2 frames
/usr/local/lib/python3.6/distpackages/pandas/core/indexing.py in _validate_integer (self, key, axis)
1435 len_axis = len (self.obj._get_axis (axis))
1436 if key>= len_axis or key<len_axis:
>1437 raise IndexError ("single positional indexer is outofbounds")
1438
1439 #  
IndexError: single positional indexer is outofbounds

Answer # 1
Related articles
 python  i want to find the number of data per row in pandas dataframe
 python  count by element with pivot_table in pandas
 python  how to count the number of characters in a character string including a regular expression
 google analytics  i want to count the number of accesses by data on the google site
 python  when you want to judge by the number of characters from the back with a regular expression
 python  the date format when reading csv data with pandas and graphing it does not work
 how to count days of the week python
 count the number of types of c language array elements
 how do i merge dataframes inside a python pandas function?
 where is the minor version number of python that starts by default specified?
 python 3x  the reading of the expression in the excel file in pandas becomes nan
 python  about pandas, gspread
 i want to count the number of keystrokes in java and make a conditional branch
 python  valueerror: field'id' expected a number but got'suzukitadashi'
 python pandas pivot_table is not reflected
 python  sumy by specifying the maximum number of characters with sumy
 python  how to load multiple time formats with pandas
 python  how to count url clicks in django and record them in the db
 python  how to accept number input even if keypressevent is defined for qlineedit in pyside
 if the integer in the table created by dataframe and the ejected integer are the same, i want to make a conditional branch
 csv  unable to delete row in pandas
 python 3x  i get lost when extracting columns in a dataframe
 python 3x  how to extract data that meets the value conditions from another data frame based on the value of one data frame
 python  about the process of extracting the canceled data based on the absolute value in the data frame
 for  how to create a table in python that shows all the experimental combinations
 python 3x  pandas: about line feed characters when outputting txt
 python 3x  dataframe column labels are unchanged
 python 3x  i'm not sure how to index pandas df
 python 3x  i don't understand how to handle multiindex in pandas
It's pretty omission, but isn't this what you expected?
For iterrows (), see here (https://note.nkmk.me/pythonpandasdataframeforiteration/).