csvfile = pd.DataFrame(columns=['Name','Age','Job','Qualifications'])
emptydataframe = pd.DataFrame(columns=['Name','Age'])
row1 = next(csvfile.iterrows())
for index, row1 in csvfile.iterrows():
if row['Name'] == Jon:
Asked
Active
Viewed 29 times
1

cs95
- 379,657
- 97
- 704
- 746
-
[Do not iterate over a dataframe.](https://stackoverflow.com/a/55557758/4909087) – cs95 Apr 14 '19 at 00:33
-
emptydataframe = csvfile[csvfile['Name'] == Jon][['Name', 'Age']] – Bas Apr 14 '19 at 00:36
-
What I don't understand is how to select a row based on values in the current row and next row and possibly next row etc. A sequence of values – Apr 14 '19 at 00:39
-
Then provide more information in your question, so we can understand what you mean. – Erfan Apr 14 '19 at 00:43
-
Why would you want to do that ? – Bas Apr 14 '19 at 00:45
-
Because I'm looking for sequences in the dataframe. So I want to extract any row where lets say 'Age' in the current row is 30 and the next row 'Age' is 40. If this sequence appears then copy the current row 'Name' and 'Age', so 'Jon', '30' into the empty first row of emptydataframe and continue to look for these sequences throughout the csvfile – Apr 14 '19 at 00:57
-
You could use DataFrame.diff() for that. And select all rows where the diff value satisfies your criteria (e.g. is positive). – Bas Apr 14 '19 at 01:17
-
What about strings? Say I wanted to select a row where the current row is 'Jon' and next is 'Sam' and every time this pattern could been seen extract the column values for current row, eg. 'Name', 'Age', 'Occupation' – Apr 14 '19 at 10:12
-
I have explained it a bit better in this post. https://stackoverflow.com/questions/55680822/how-do-you-search-through-a-row-row-1-of-a-csv-file-but-search-through-the-ne?noredirect=1#comment98052260_55680822 – Apr 15 '19 at 11:07