1
votes
def delinquent(data):
#loops through each time of the mortgage performance review
for time in len(data.index)):
    data.index[data.columns == "1"]

Pre Warning I'm very much a beginner at pandas and dataFrames

I'm trying to see if a loan at any point in its progression went delinquent. I have created a df of each loan as a row (29962), and each column (26) is a specific time (month_year) when the loan status was reviewed. If the loan was reported as delinquent, in any month_year column, the value for that loan in that specific column would be "1".

In the code above I tried to use an a for loop iterate through the rows checking the values of each column for "1". I want the code to return True or False, then if possible make a new column Labeled "delinquent" shows whether or not (T/F) a loan ever went delinquent. I'd like to add that new column back to my original dataFrame (called nsmo) so I can look at the accuracy of credit scores (at the origination of the loan) in predicting whether or not a loan will go delinquent.

Thank you, apologies for the burden of my question.

I'm using py 3 and pandas

1
Can you provide some sample input and the corresponding output? See minimal reproducible example, How to Ask, help center.AMC

1 Answers

3
votes

Try this:

df['delinquent'] = df.eq('1').any(axis=1)

But be careful with your datatypes. The string '1' sounds like it should be the number 1, or better yet, True and False.