Updated for comment below
I believe the short answer is no to
Is there someway of saying "change the row you've already fetched"
This is because operations in Pandas return a copy not a view to the original DataFrame. There is a StackOverflow post from JeffR who writes much of Pandas here
If you're trying to assign the val
to one cell in the DataFrame you can use the set_value
function. The documentation for that method is here.
val = "123"
row = df.loc[id, :]
t = type(row['col1'])
val = t(val)
df.set_value(id, 'col1', val)
If you're trying to assign the val
with particular data type to all cells in column, can use the apply method
def changeType(cell, val):
# You could pass the id or list of ids as well if you need to perform some logic with it
t = type(cell)
cell = t(val)
return cell
val = "123"
df.loc[:, 'col1'] = df.loc[:, 'col1'].apply(changeType, args=(val,))