pandas replace word begins with contains

df['sport'] = df.sport.str.replace(r'(^.*ball.*$)', 'ball sport')
df

5
2

                                    df.sport = df.sport.apply(lambda x: 'ball sport' if 'ball' in x else x)

5 (2 Votes)
0
4.83
6

                                    In [71]:
df.loc[df['sport'].str.contains('ball'), 'sport'] = 'ball sport'
df

Out[71]:
    name       sport
0    Bob      tennis
1   Jane  ball sport
2  Alice  ball sport

4.83 (6 Votes)
0
4
7
Deadcode 90 points

                                    df.sport.str.replace(r'(^.*ball.*$)', 'ball sport')

0        tennis
1    ball sport
2    ball sport
Name: sport, dtype: object

4 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
replace all substring words in dataframe how to replace value ina string pandas If value in row in DataFrame contains string rename if dataframe column contains value change value python pandas dataframe string manipulation inplace replace python pandas dataframe string manipulation replace change all strings in pandas replace function pandas pandas replace if contains replace if contains replace in lambda pandas replace pandas series values based on time index pandas replace python pandas dataframe replace column values containing text in list python pandas dataframe replace column values containing text panda search replace pandas replace series replace string with chacter pandas replace the value in data frame if it maches a sub string myDF ['mySeries'].str.replace('[', '').str.replace(']', '') string replace pandas pandas replace string values modify string value in dataframe how to replace string with a number of characters in pandas replace after character pandas pandas replace string regex lreplace conatins pandas columns contain pandas replace python data.str.replace change string value if it contains substring pandas python dataframe replace string in column str contains pnadas dataframe replkace replace str contains numeber pandas replace str contains pandas pandas replace string in a column find substring and replace entire string python rename value if string found python replace value based on str contain python replace value based on str contains condition python pandas if str contains = True, then replace value in python string contains then replace python if string contains replace python if string contains then replace python pandas dataframe replace part of string replace a string in pandas dataframe pandas if column contains string change pandas dataframe string search and replace pandas dataframe convert string search and replace pandas how to edit a dataframe cotents string change string into series python replace string python pandas replace string pandas column df str replace replace string in pandas column replace strings in dataframe python pandas replace string values in column replace contains pandas replace string in a column pandas replace parts of strings in pandas column replace last part of a string in pandas column pandas inplace in string method replace pandas string pandas replace string startswith pandas column find and replace replace sub string from pandas replace part of string dataframe pandas apply lambda replace string how to replace string in pandas dataframe pandas apply string replace to column python series replace string perform replace on string in pandas series replace a string in pandas
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source