import pandas as pd
df = pd.DataFrame({'ID': ['A', 'C'],
'Text' : ['yes', 'no'],
'Value' : ['1', '1']
}
)
# set the id as index
df.set_index('ID', inplace=True)
# use index to raplace value
df.loc['C','Value'] = 0
# reset index
df.reset_index(inplace=True)
# same operation can be done using iloc
# as an example use numeric position to revert back
df.iloc[1, 2] = 1
使用基于标签的索引.loc如何:
或者使用基于索引的.iloc:
使用
np.where
因为你要求特别使用位置。有两种方法可以做到。使用
loc
和iloc
(数字位置)相关问题 更多 >
编程相关推荐