Advertisement
elena1234

changing values in dataframe in Python

Mar 4th, 2023 (edited)
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | Source Code | 0 0
  1. # Changing values in a column
  2. titanic.loc[1:3, "age"] = 42
  3. titanic.loc[1:4, 3] = [43, 44, 45]
  4. titanic.loc[titanic.age < 1, "age"] = 1
  5.  
  6. # Changing values in a row
  7. titanic.loc[0, "survived" : "sex"] = [1, 1, "female"]
  8.  
  9. ######################################
  10. titanic.replace(0, "Zero")
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement