Find and replace strings in Excel (.xlsx) using Python

后端 未结 4 1370
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 02:00

I am trying to replace a bunch of strings in an .xlsx sheet (~70k rows, 38 columns). I have a list of the strings to be searched and replaced in a file, formatted as below:-

4条回答
  •  太阳男子
    2021-01-07 02:50

    Make 2 arrays A[bird produk, pig, ayam, kuda] //words to be changed B[bird product, pork, chicken, horse] //result after changing the word

    Now check each row of your excel and compare it with every element of A. If i matches then replace it with corresponding element of B.

    for example // not actual code something like pseudocode

    for (i=1 to no. of rows.)
    {
    for(j=1 to 200)
    {
    if(contents of row[i] == A[j])
    then contents of row[i]=B[j] ;
    break;
    }
    }
    

    To make it fast you have to stop the current iteration as soon as the word is replaced and check the next row.

提交回复
热议问题