Home > Enterprise >  Unable to assign different values in each cell of a column in dataframe, containing 99,000 records
Unable to assign different values in each cell of a column in dataframe, containing 99,000 records

Time:12-08

I want to change values greater than 70 in column CT_feat7 but it only changes till 59000, after that I have to run the iteration again, with a different index value. Please explain as to why this happens?? and is there a better way???? dataset before replacement

for index,j in enumerate(df['CT_feat7']):
  if j>70:
    df.loc[index,'CT_feat7'] = 11 random.random()

After I run this,values in the dataset changed only upto index 59180.

i,j = 59180,2
while i <= 99195:
  if df.loc[i,'CT_feat7']>70:
    df.loc[i,'CT_feat7'] = j
    j =0.1
    if j>12:
      j=2
  i =1

CodePudding user response:

I think it is because enumerate is not the proper iterator to use with .loc. Try:

for index,j in df['CT_feat7'].items():
  if j>70:
    df.loc[index,'CT_feat7'] = 11 random.random()
  • Related