1

Basically my problem is that I'm trying to create a code that will use Pandas to skip x amount of rows until it reaches a row containing records named departmentName and departmentID. This has been troubling for me because nearly all the questions I've seen have asked about how to skip a specified number of rows but with this issue, there is no specified amount of rows that will be skipped, it could be any amount. So I need a formula that will automatically adapt to this issue. Any ideas?

Unamed_1 Unamed_2
Credits
1 Math
2 Computer Science
3 History
4 Deep Learning

This what I have done so far:

for index_1, row_1 in df_cmd.iterrows():
    if row_1.notnull().all():

I want to get the name of the row

j__carlson
  • 1,346
  • 3
  • 12
  • 20
Blake McLaughlin
  • 91
  • 1
  • 2
  • 11
  • 2
    Does this answer your question? [Python Pandas: Get index of rows which column matches certain value](https://stackoverflow.com/questions/21800169/python-pandas-get-index-of-rows-which-column-matches-certain-value) – Cfomodz Aug 17 '21 at 18:16

3 Answers3

0

I cannot say that I perfectly understand what you mean but I recommend you to check the "edit part" of this question. pandas import specific part of table

Dharman
  • 30,962
  • 25
  • 85
  • 135
eyup.tatar
  • 75
  • 8
0

I'm not 100% sure what you have in mind, but maybe you should try

df.loc[['departmentName']]

I want to get the name of the row

do you mean the index? you said the name of the row yourself

adamDud
  • 309
  • 1
  • 3
  • 10
0

If I can get you right.

Lets take some df as example:

col2 = ["Math",
"Computer Science",
"History",
"Deep Learning",
"departmentName",
"departmentID",
"More",
"And more",
"And even more"]

test = pd.DataFrame(col2, columns = ["Dep"])

Than this way you can get a needed index:

index = test.index[test["Dep"] == "departmentName"][0]

And that way you get everything after the row with that index:

test.iloc[index:]

Watch out if there will be more than 1 row with that value.