0

I am working on a code to print the row in an excel sheet with today's date. Here is the model how the sheet looks like.

Date Day Column1 Column2 Column3

1 Monday Value Value Value

If today's date is 1/anymonth/anyyear I want to print that particular row.[1 Monday Value Value Value]

Below is my python code to print the whole sheet

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
import xlrd
import io
import pandas as pd
#target url taken from sharepoint and credentials
url = 'https://epiuse-my.sharepoint.com/:x:/r/personal/xxx/Documents/xxx%20xxx%xxx%20xxx%202021.xlsx?'
username = 'email id'
password = 'password'
relative_url = 'personal/xxx/_layouts/15/Doc.aspx?sourcedoc=%7B765306EC-3217-4BC1-B32C-689C5B4B1F2B%7D&file=xxx%202021.xlsx'
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
  ctx = ClientContext(url, ctx_auth)
  web = ctx.web
  ctx.load(web)
  ctx.execute_query()
  print("Authentication successful")
filename = 'xxx%20xxx%xxx%20xxx%202021.xlsx'
with open(filename, 'wb') as output_file:
    response = File.open_binary(ctx, relative_url)
    output_file.write(response.content)
response = File.open_binary(ctx, relative_url)
#save data to BytesIO stream
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0) #set file object to start
#read file into pandas dataframe
df = pd.read_excel(bytes_file_obj)
print(df)
  • `print(df)` prints the entire DataFrame as you've noticed but you want to print only a certain row from that DataFrame so your question is not specific to Excel. Post a [mre] with just a DataFrame populated with a sample of your data then indicate what row within that DataFrame you want to be printed. –  Mar 24 '21 at 20:42
  • See https://stackoverflow.com/questions/17071871/how-to-select-rows-from-a-dataframe-based-on-column-values –  Mar 24 '21 at 20:43

0 Answers0