0

The code below doesn't work because AttributeError: 'Series' object has no attribute 'startswith'. How do I do get this code to work?

#Starts with account num and negative
negExpense = (df.Amount < float(0)) & \
            (df.loc[df['Account'].startswith(5)])
print(negExpense)
debits.to_excel(writer, 'Negative Expense')

2 Answers2

0

Try using Pandasql to use reg-exp. You can manipulate your dataframe using pandasql library and replacing the earlier df with new_df.

0

You can use df.str.startswith(5) instead of just startswith.

This link will help you out for further info - pandas select from Dataframe using startswith

mohammed_ayaz
  • 620
  • 11
  • 16