Python Forum
Select a value from Dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select a value from Dataframe
#1
Hi,

How do I select a value from a column in my df, a value that start with a character, small or capital followed by numbers.

This is my code
search = ["S", "s"]

bool_series = df["UserName"].str.startswith(tuple(search), na = False)
df = results[bool_series]
So I want a value that starts with S or s then followed by any numbers. E.g I don't want S98OS1, but S78345
Reply
#2
df['un_part'] = df.UserName.str[1:]
df = df[df.un_part.str.isnumeric()]
Reply
#3
try below code:
df = pd.DataFrame({"username":["s123","s123a","abcd","efg","S345"]})
result = df["username"].str.match(r"^s\d+$", case=False)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SQL select join operation in python(Select.. join) pradeepkumarbe 1 2,232 Feb-14-2019, 08:34 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020