daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BrandName Specialty
  2. A          H
  3. B          I
  4. ABC        J
  5. D          K
  6. AB         L
  7.      
  8. >>> df['BrandName'].replace(['ABC', 'AB'], 'A')
  9. 0    A
  10. 1    B
  11. 2    A
  12. 3    D
  13. 4    A
  14.      
  15. df['BrandName'] = df['BrandName'].replace(['ABC', 'AB'], 'A')
  16.      
  17. DataFrame.replace(
  18.         to_replace=None,
  19.         value=None,
  20.         inplace=False,
  21.         limit=None,
  22.         regex=False,
  23.         method='pad',
  24.         axis=None)
  25.      
  26. df['BrandName'].replace(
  27.     to_replace=['ABC', 'AB'],
  28.     value='A',
  29.     inplace=True
  30. )
  31.      
  32. mydf = pd.DataFrame({"BrandName":["A", "B", "ABC", "D", "AB"], "Speciality":["H", "I", "J", "K", "L"]})
  33. mydf["BrandName"].replace(["ABC", "AB"], "A", inplace=True)
  34.      
  35. df.loc[df['BrandName'].isin([ABC', 'AB'])]='A'
  36.      
  37. import pandas as pd
  38. dk=pd.DataFrame({"BrandName":['A','B','ABC','D','AB'],"Specialty":['H','I','J','K','L']})
  39.      
  40. dk.BrandName.replace(to_replace=['ABC','AB'],value='A')
  41.      
  42. df = pd.DataFrame(np.random.randint(0,10,size=(100, 4)), columns=list('ABCD'))
  43.  
  44. def loc():
  45.     df1.loc[df1["A"] == 2] = 5
  46. %timeit loc
  47. 19.9 ns ± 0.0873 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
  48.  
  49.  
  50. def replace():
  51.     df2['A'].replace(
  52.         to_replace=2,
  53.         value=5,
  54.         inplace=True
  55.     )
  56. %timeit replace
  57. 19.6 ns ± 0.509 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top