There is an excel file, countries are abbreviated in it in a column:

CA US US ... 

How to display the excel file in which the number will be written in the first column, and in the second the abbreviated name from this country?

  • What did you do? Give an example of code that does not work for you. - Mr. Brightside
  • Yes, really nothing, I'm in Python 0 (like programming - Denis Sybin
  • import openpyxl from openpyxl import load_workbook wb = load_workbook ('./ Task 2.xlsx') w1 = wb ["installs"] w2 = wb ["purchases"] city = w1 ['B'] city_set = set (city) row_number_1 = w1.max_row row_number_2 = w2.max_row ps = [] unswer = [] p = 1 for i in range (0.5): j = 1 while city [j] .value == city [1 + j] .value : j = j + 1 p + = 1 ps.append (p) print (ps) - Denis Sybin
  • @DenisSybin, can you put an Excel example on any file sharing service? - MaxU 10:31 pm
  • And where can the thread be in lichku, otherwise it’s not mine, they were asked to figure it out, they would suddenly curse) - Denis Sybin

1 answer 1

Option using the Pandas module:

 import pandas as pd # pip install pandas input_fn = r'C:\download\Task.xlsx' output_fn = r'c:\temp\result.xlsx' df = pd.read_excel(input_fn, header=None, skiprows=[156], names=['device_id', 'country', 'install_time']) # расчет количества строк по странам и запись в Excel (df.groupby('country') .size() .reset_index(name='count') .to_execl(output_fn)) 
  • You are just a god, thank you. And can you completely do it?) Atoh, I am generally stupid - Denis Sybin
  • @ DenisSybin, SO works a little differently;) It is customary to ask one technical question with which there were difficulties. This may be useful to those who get to this question from search engines. It is not customary to ask several questions at once within the framework of a single SO issue or to solve whole tasks here — this is unlikely to be able to help anyone else ... Therefore, I advise you to divide your task into stages and gradually solve them. If questions arise at any stage, ask a new SO question. It is also considered good form to indicate in the question the attempts to solve, even if the code is non-working / ugly - MaxU