Py学习  »  Python

python:在Excel中循环索引并替换为字符串

Nick • 4 年前 • 865 次点击  

enter image description here

现在我要做的是循环遍历A列中的每个索引单元格,并为所有单元格分配相同的值,直到到达下一个0。例如:

enter image description here

谢谢你抽出时间

编辑: s.index=pd.Series((s.index==0).cumsum()).map({1:'bananas',2:'cherries',3:'pineapples'})

只需输入A列中所有单元格的第一个元素(香蕉)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54946
 
865 次点击  
文章 [ 1 ]  |  最新文章 4 年前
YOBEN_S
Reply   •   1 楼
YOBEN_S    5 年前

假设你有数据帧 s cumsum

s.index=pd.Series((s.index==0).cumsum()).map({1:'bananas',2:'cherries',3:'pineapples'})