0
   TTT
1. 802010001-999-00000285-888-
2. 256788
3. 1940
4. NaN
5. NaN
6. 702010001-X-2YZ-00000285-888-

I want to Fill column GGT column with all other values except for the amounts

Required table would be like this

   TTT                                GGT
1. 802010001-999-00000285-888-        802010001-999-00000285-888-
2. 256788                             NaN
3. 1940                               NaN
4. NaN                                NaN
5. NaN                                NaN
6. 702010001-X-2YZ-00000285-888-      702010001-X-2YZ-00000285-888-

the orginal table has more than 200thousands rows.

0

2 Answers 2

1

If you want to remove the rows with only numbers, you can use the match() method of the string elements of the column TTT. You can use a code like that :

df["GGT"] = df["TTT"][df["TTT"].str.match(r'^(\d)+$')==False]
Sign up to request clarification or add additional context in comments.

Comments

1

Use Series.mask:

df['GGT'] = df['TTT'].mask(pd.to_numeric(df['TTT'], errors='coerce').notna())

Or:

df['GGT'] = df['TTT'].mask(df["TTT"].astype(str).str.contains('^\d+$', na=True))
print (df)
                             TTT                            GGT
0    802010001-999-00000285-888-    802010001-999-00000285-888-
1                         256788                            NaN
2                           1940                            NaN
3                            NaN                            NaN
4  702010001-X-2YZ-00000285-888-  702010001-X-2YZ-00000285-888-

I

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.