xyzzz and dont want to change a single thing other than this and save the file back in the excel format.

问题描述 投票:0回答:1
When reading the file in pd.read_excel it formats some data(messes up the columns,unnamed etc), how else should I do this in python?

P.S- there's a one row footer in the end as well

https:

我有一个excel表格,其中有一些页眉和页脚以及中间的数据,现在我想编辑中间的一列数据框架,这样我就不想改变任何其他东西。你可以在链接中看到这一列,以及照片中的LOAN NO。例如,在给定的数据集中,我想把第6行的贷款号改为xyzzz从abcd/drive.google.comfiled1gJ97HpG3OJlrcQswI2BIWLsZluza4PEmview?usp=drivesdk。

这里是数据集的链接。

Here's a screen shot

python pandas numpy xlsxwriter pandas.excelwriter
1个回答
1
投票

你可以尝试这样的东西

import pandas as pd
import xlrd
# pip install openpyxl
df = pd.read_excel('./sample23.xlsx', 'Sheet0', header=None)
def change(x):    
    try:
        if x != 'abcd|xyzzz' and x == 'Loan No.':
            return x
        elif x == 'abcd|xyzzz':
            return 'xyzzz' 
    except Exception as e:
        return x


df[6] = df.apply(lambda row: change(row[6]), axis=1)
df.to_excel("test.xlsx",sheet_name='Sheet0', header=None, index=None)

df.head(10)
© www.soinside.com 2019 - 2024. All rights reserved.