JavaScript
x
12
12
1
Cities = ['Acre','Ashdod','Ashqelon','Bat Yam','Beersheba','Bnei Brak','Caesarea','Dimona','Dor','Elat','Kefar Sava','Lod','Meron','Nahariyya','Nazareth','Netanya']
2
3
lst = []
4
5
for i in range(500):
6
7
i = random.choice(Cities)
8
print(i)
9
lst.append(i)
10
11
Data.loc[(Data['country'] == 'Israel') & (Data['state'] == 0),'state'] = lst
12
I tried this method. In this code list some city of israel and generate 500 random value of it. And apply condition to insert data in israel state location where data is 0.
Advertisement
Answer
JavaScript
1
7
1
# mask data so you compute mask only once
2
mask = (Data['country'] == 'Israel') & (Data['state'] == 0)
3
# find the length
4
len_to_replace = len(Data[mask])
5
# replace
6
Data.loc[mask, 'state'] = [random.choice(Cities) for _ in range(len_to_replace)]
7