Pandas 引用和索引
Pandas referencing and indexing
考虑我的数据框为:
Name Visits
0 A 0
1 B 0
2 C 0
3 D 0
4 E 0
现在,我想将仅E或任何其他特定人员的访问量更改为任意随机数,我该怎么做?比如我如何具体提及任何一个人的访问,比如 E 并更改他们的访问?我尝试阅读文档,但没有帮助。请帮忙。谢谢。
使用 loc 和 numpy 的 randint 函数:
# change the randint range to whatever you want
df.loc[df['Name'] == 'E', 'Visits'] = np.random.randint(0,100)
考虑我的数据框为:
Name Visits 0 A 0 1 B 0 2 C 0 3 D 0 4 E 0
现在,我想将仅E或任何其他特定人员的访问量更改为任意随机数,我该怎么做?比如我如何具体提及任何一个人的访问,比如 E 并更改他们的访问?我尝试阅读文档,但没有帮助。请帮忙。谢谢。
使用 loc 和 numpy 的 randint 函数:
# change the randint range to whatever you want
df.loc[df['Name'] == 'E', 'Visits'] = np.random.randint(0,100)