[Jupyter Notebook] Error using pandas and pyperclip

Hello everyone,

Im using pandas and pyperclip to copy and paste some info to register costumers in Excel to my website. However, I can’t copy any cell in Excell who iniciates with 0. For example: the zip cods who starts with 095… the code only copy the 95…

See below part of the code:

import pyautogui
import pyperclip
import time
import pandas as pd

pyautogui.PAUSE = 4

tabela = pd.read_excel(r"C:\Users\Appmax\Desktop\Ids.xlsx")

for i in range(99):
pyautogui.hotkey(‘win’,‘s’)
pyautogui.write(‘chrome’)
pyautogui.press(‘enter’)
link = ‘link to website’
pyperclip.copy(link)
time.sleep(10)
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘enter’)
time.sleep(18)
pyautogui.click(x=291, y=316)
tabela = pd.read_excel(r"C:\Users\Appmax\Desktop\Ids.xlsx")
Nome = []
Sobrenome = []
Email = []
Telefone = []
CPF = []
CEP = []
Rua = []
Nr = []
Complemento = []
Bairro = []
Cidade = []
for i in tabela[‘Nome’]:
Nome.append(str(i))
for i in tabela[‘Sobrenome’]:
Sobrenome.append(str(i))
for i in tabela[‘E-mail’]:
Email.append(str(i))
for i in tabela[‘Telefone’]:
Telefone.append(str(i))
for i in tabela[‘CPF’]:
CPF.append(str(i))
for i in tabela[‘CEP’]:
CEP.append(str(i))
for i in tabela[‘Rua’]:
Rua.append(str(i))
for i in tabela[‘Nr’]:
Nr.append(str(i))
for i in tabela[‘Complemento’]:
Complemento.append(str(i))
for i in tabela[‘Bairro’]:
Bairro.append(str(i))
for i in tabela[‘Cidade’]:
Cidade.append(str(i))
pyperclip.copy(Nome[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
time.sleep(2)
pyperclip.copy(Sobrenome[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
time.sleep(2)
pyperclip.copy(Email[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
time.sleep(2)
pyperclip.copy(Telefone[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
time.sleep(2)
pyperclip.copy(CPF[0])
pyautogui.hotkey(‘ctrl’,‘v’)
time.sleep(2)
pyautogui.press(‘tab’)
time.sleep(2)
pyautogui.press(‘tab’)
time.sleep(2)
pyperclip.copy(CEP[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
time.sleep(2)
pyautogui.click(x=856, y=113)
pyautogui.hotkey(‘ctrl’,‘a’)
pyperclip.copy(Rua[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
pyperclip.copy(Nr[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
pyperclip.copy(Complemento[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
pyperclip.copy(Bairro[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
pyperclip.copy(Cidade[0])
pyautogui.hotkey(‘ctrl’,‘shift’,‘v’)
pyautogui.press(‘tab’)
pyautogui.click(x=1224, y=438)
time.sleep(6)
pyautogui.write(‘Appmax Recuperação de Chargebacks’)
time.sleep(6)
pyautogui.click(x=1273, y=510)
time.sleep(20)

Thanks for your attention and sorry for my poor english. Any doubts, feel free to ask!

This doesn’t seem like a Jupyter issue. I believe you’d get the same result if you ran your code in Python or IPython. In other words it is off-topic for this Discourse forum.

That being said…
While I’m unclear what you are copying in what direction, I’m going to guess when you read in from Excel to Pandas, it is casting the zip codes to integers? If that is the case, then you want to learn about using the dtype option in your pd.read_excel() step to supply information to treat that column as object. That way the data there will remain as string and nothing dealing with numerics will simplify it. See here.


Part of the problem understanding your posted code is that it looks like you didn’t post the code correctly and the formatting is gone. As whitespace matters a lot in Python, you should check this Discourse post here about posting code. Most of those approaches work in other forums that accept markdown-formatted text as well and so the same approaches can usually be used in more appropriate forums.

1 Like

Thanks for your ankswer.

I already trying to format the numbers in Excel, but the problem persists with number 0. I do made a lot of changes, formating cells to the first number 0 shows in the formula bar. However, all other numbers who don’t starts with 0 works correctly…

If the problem is within Excel, this definitely isn’t the place to find help. There’s a host of issues with relying on Excel for data handling. That’s why the less you involve it and use tab- or comma- delimited files and Pandas in Python (or the language R), you’ll have a much happier time analyzing data. (For a long time it was just data geeks trying to fight this battle; however, lately there’s even been some high profile cases in the news about the trouble that misconceptions about using Excel for data management and analysis can cause, such as here, here, and here.)
Understandably sometimes it is out of your hands because the data in Excel is what you inherit or is what others insist you use so they can work with you.

Have you searched elsewhere there’s a lot of resources on the issue of putting zeros in front:

If I am misunderstanding and the problem isn’t in the Excel part, I’d be happy to help with the Python and Pandas stuff; however, you’d have to share a minimum reproducible example. It wouldn’t need to involve the pyautogui stuff, unless I am misunderstanding.

1 Like