Python Forum
Help with Integration Pandas excel - Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Integration Pandas excel - Python
#1
I'm fascinated with the programming area and yesterday I started to study Python on Youtube.

I started to make a video class, I had some setbacks, but I managed to solve it by searching, but I have this error that I couldn't fix. I would like some help if possible. I thank you very much in advance.

each worksheet has two columns (salesperson and $sales), in one of the worksheets, there is a salesperson who has reached a value above one thousand reais.

in the exercise, programming line, the idea was to give the RUN, generate the information from the spreadsheets and show which month the award-winning seller has.

However, he only plotted the month of January, February and March.

Attached Files

Thumbnail(s)
       
Reply
#2
programation

Attached Files

Thumbnail(s)
   
Reply
#3
Don't post Images, post your code in python tags (the python button)
Reply
#4
Thanks Axel for observation,

# MODULOS
# pandas (integracao com excel)
# openpyxl (integracao com excel)
# xlrd (nao sei pq)
# twilio (envia sms)

import pandas as pd

# PASSO A PASSO DA SOLUCAO
# ABRIR AS 3 PLANILHAS - ok
lista_meses = ['Janeiro', 'Fevereiro', 'Marco']

for mes in lista_meses:
print(mes)
tabela_vendas = pd.read_excel(f'{mes}.xls')
print(tabela_vendas)
if (tabela_vendas['Vendas'] > 1000).any():
print(f'no mes {mes} o encontrou um vendedor com mais de R$1000,00')

_______________________


"C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\Scripts\python.exe" "C:/Users/Pichau/PycharmProjects/Analise Bonus Viagem/main.py"
Janeiro
Unnamed: 0 Unnamed: 1
0 Vendedor Vendas
1 Vendedor 1 10005
2 Vendedor 2 250
3 Vendedor 3 300
4 Vendedor 4 22
5 Vendedor 5 258
6 Vendedor 6 5
7 Vendedor 7 555
8 Vendedor 8 457
9 Vendedor 9 44
10 Vendedor 10 335
11 Vendedor 11 888
12 Vendedor 12 6
13 Vendedor 13 333
14 Vendedor 14 887
15 Vendedor 15 998
16 Vendedor 16 987
17 Vendedor 17 658
18 Vendedor 18 156
19 Vendedor 19 325
20 Vendedor 20 545
Traceback (most recent call last):
File "C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\lib\site-packages\pandas\core\indexes\base.py", line 3621, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Vendas'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\main.py", line 18, in <module>
if (tabela_vendas['Vendas'] > 1000).any():
File "C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\lib\site-packages\pandas\core\frame.py", line 3505, in __getitem__
indexer = self.columns.get_loc(key)
File "C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\lib\site-packages\pandas\core\indexes\base.py", line 3623, in get_loc
raise KeyError(key) from err
KeyError: 'Vendas'

Process finished with exit code 1
Reply
#5
I have to repeat myself, please post your code in python tags (the python button, blue yellow)

[Image: python-logo-glassy.png]
Reply
#6
I'm sorry, because I am new here and in the system, I believe that what you asked me is below

_______________________

PROGRAM

import pandas as pd

lista_meses = ['Janeiro', 'Fevereiro', 'Marco']

for mes in lista_meses:
print(mes)
tabela_vendas = pd.read_excel(f'{mes}.xls')
print(tabela_vendas)
if (tabela_vendas['Vendas'] > 1000).any():

ERROR
"C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\Scripts\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\pydevconsole.py" --mode=client --port=50368
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['C:\\Users\\Pichau\\PycharmProjects\\Analise Bonus Viagem', 'C:/Users/Pichau/PycharmProjects/Analise Bonus Viagem'])
PyDev console: starting.
Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)] on win32
runfile('C:/Users/Pichau/PycharmProjects/Analise Bonus Viagem/main.py', wdir='C:/Users/Pichau/PycharmProjects/Analise Bonus Viagem')
Janeiro
Unnamed: 0 Unnamed: 1
0 Vendedor Vendas
1 Vendedor 1 10005
2 Vendedor 2 250
3 Vendedor 3 300
4 Vendedor 4 22
5 Vendedor 5 258
6 Vendedor 6 5
7 Vendedor 7 555
8 Vendedor 8 457
9 Vendedor 9 44
10 Vendedor 10 335
11 Vendedor 11 888
12 Vendedor 12 6
13 Vendedor 13 333
14 Vendedor 14 887
15 Vendedor 15 998
16 Vendedor 16 987
17 Vendedor 17 658
18 Vendedor 18 156
19 Vendedor 19 325
20 Vendedor 20 545
Traceback (most recent call last):
File "C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\lib\site-packages\pandas\core\indexes\base.py", line 3621, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Vendas'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/Pichau/PycharmProjects/Analise Bonus Viagem/main.py", line 18, in <module>
if (tabela_vendas['Vendas'] > 1000).any():
File "C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\lib\site-packages\pandas\core\frame.py", line 3505, in __getitem__
indexer = self.columns.get_loc(key)
File "C:\Users\Pichau\PycharmProjects\Analise Bonus Viagem\venv\lib\site-packages\pandas\core\indexes\base.py", line 3623, in get_loc
raise KeyError(key) from err
KeyError: 'Vendas'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 1,696 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
  Active Directory integration dady 2 465 Oct-13-2023, 04:02 AM
Last Post: deanhystad
  Need Help! Pandas EXCEL PIVOT psb3958 1 915 Nov-13-2022, 10:37 PM
Last Post: deanhystad
  export into excel, how to implement pandas into for-loop deneme2 6 2,361 Sep-01-2022, 05:44 AM
Last Post: deneme2
  Problem in saving .xlsm (excel) file using pandas dataframe in python shantanu97 2 4,163 Aug-29-2021, 12:39 PM
Last Post: snippsat
Photo Integration of apache spark and Kafka on eclipse pyspark aupres 1 3,701 Feb-27-2021, 08:38 AM
Last Post: Serafim
  Tableau Time Series Prediction using Python Integration tobimarsh43 0 1,888 Jul-24-2020, 10:38 AM
Last Post: tobimarsh43
  identical cells in 2 different excel sheets python pandas esso 0 1,598 Jul-19-2020, 07:50 PM
Last Post: esso
  R-PYTHON INTEGRATION RELATED PROBLEM arnab93 0 1,418 Jun-05-2020, 02:07 PM
Last Post: arnab93
  STATA/Python Integration jprender 0 1,804 May-03-2020, 09:38 PM
Last Post: jprender

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020