I have a pandas dataframe containing columns extracted from a csv file. One of the columns has strings which contain a particular number, I want to extract. It showed a TypeError
, which I think was because of the object data type of the column, but neither does setting data type of the column during extraction work, nor does astype
work on the particular column. Earlier, I extracted the same column from the Excel file, and the regex expression worked on it, no problem.
The working head is as follows:
Transaction Date PARTICULARS DEPOSITS WITHDRAWALS Amount Dr/Cr Calc_Amount Calc RRN Number RRN-AMT
0 2019-05-30 UPI/914923281641/UPI/raghu.m.v2016@o/ 0 32.86 32.86 Dr 32.86 914923281641 0100
1 2019-05-30 UPI/915000512028/UPI/hemanth1999kuma/ 0 0.95 0.95 Dr 0.95 915000512028 0100
2 2019-05-30 UPI/RVSL915000512028/UPI/hemanth1999kuma/ 0.95 0 0.95 Cr -0.95 915000512028 0100
3 2019-05-30 UPI/914923451855/UPI/tpmanzoor55@okh/Federal Bank 1.19 0 1.19 Cr -1.19 914923451855 0100
4 2019-05-30 UPI/914923339262/UPI/ravimaurya8735@/ 0 0.94 0.94 Dr 0.94 914923339262 0100
From this code:
for i, row in bank_statement_30May.iterrows():
result = [e for e in re.split("[^0-9]",row[1]) if e != '']
bank_statement_30May.loc[i,"Calc RRN Number"] = max(map(int,result))
This is the error from the second code:
result = [e for e in re.split("[^0-9]",row[1]) if e != '']
File "C:\Users\Suraj Joshi\AppData\Local\Programs\Python\Python37\lib\re.py", line 213, in split
return _compile(pattern, flags).split(string, maxsplit)
TypeError: cannot use a string pattern on a bytes-like object