I know, this is an easy question, but I checked so many sites on the internet and couldn't find the problem that I have.
I have a dataframe and one column of this dataframe is for brand. I wanted to give specific numbers for these brands to make brand aggregation easier.
import pandas as pd
last = pd.read_pickle('pre_clustering.pkl')
random_number=9288
first=""
f=0
for i in last['brand']:
if(type(i)==str):
if(first == i):
last.at[f, 'brand']= random_number
print(last.loc[f, 'brand'])
f=f+1
elif(first !=i):
first=i
random_number= random_number +1
last.at[f, 'brand'] = random_number
print(last.loc[f, 'brand'])
f=f+1
else:
f=f+1
brand = last['brand']
This is my code and output. I tried everthing to convert them to integer, but they are still string. I controlled my if else condition to be sure by using print() and it is working as you see
What is wrong with my code? or what should I do to convert my strings to integers?