-2

I have some table which is look like this :

Cars Purchased Bike
0   0   No
1   1   No
2   2   No
3   1   Yes
4   0   Yes
... ... ...
995 2   Yes
996 0   Yes
997 0   Yes
998 3   No
999 2   Yes

I would like to create two items 0 and 1 from the Cars column 0 = if you dont have car 1= for car owners, no matter how many later, i Want to check if there is some relation between purchased bike and having car. How to do that ? Thanks !

Przemek Dabek
  • 519
  • 2
  • 14

1 Answers1

0

You can use Pandas' .loc() method:

import pandas as pd
import numpy as np

df = pd.read_csv("test1.csv")
df.loc[(df['Cars'] >= 1, 'Cars')]=1
print(df)
DapperDuck
  • 2,728
  • 1
  • 9
  • 21
  • Hi, but i need just only two columns "Cars" and "PurchasedBike" When I was trying select just only two. i got all dataframe. df[['Cars','Purchased Bike']] df.loc[(df['Cars'] >= 1, 'Cars')]=1 print(df) – Przemek Dabek Jan 17 '21 at 16:44
  • The column on the left, is the index column and can't be deleted. See this [SO answer](https://stackoverflow.com/a/20107825/12602208) – DapperDuck Jan 17 '21 at 16:47