chinna venkat
chinna venkat

Reputation: 27

How to extract comments with data using pandas?

normally when we use the read function we get data only we don't get comments, sometimes those comments are also important for analysis, so any heads up would be helpful. Thank You

Upvotes: 0

Views: 546

Answers (1)

Vikram Karthic
Vikram Karthic

Reputation: 478

comments normally are on few random cell, hence you may have to loop through rows and cells to capture comments and Pandas may not help you, you may use openpyxl to do this

from openpyxl import load_workbook

workbook = load_workbook('yourexcel.xlsx')
sheet1 = workbook.get_sheet_names()[0]
worksheet = workbook.get_sheet_by_name(sheet1)

for row in worksheet.iter_rows():
    for cell in row:
        if cell.comment:
            print(cell.comment.text)

Upvotes: 1

Related Questions