Python Forum
How to use the count function from an Excel file using Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use the count function from an Excel file using Python?
#1
Hello everyone - I am in the early stages of learning Python and decided to start with using Excel in Python. I am running the code below in Jupyter and it works well. This notebook currently has a state column and a country column. I would like to count the total number of states but I don't know how to reference the columns - could anyone please tell me how to start? I tried the second code below but that did not run.

import pandas as pd

df = pd.read_excel (r'C:\Users\Family\Desktop\Anaconda\Book1.xlsx')
print (df)
st = 'State'.count()
Reply
#2
You most always have have reference to the DataFrame,which now stored in variable df.
print(df['State'].count())
jpy likes this post
Reply
#3
Thank you for the guidance and reading, I appreciate it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  docx file to pandas dataframe/excel iitip92 1 2,366 Jun-27-2024, 05:28 AM
Last Post: Pedroski55
  Excel isnt working properly after python function is started IchNar 2 1,214 May-01-2024, 06:43 PM
Last Post: IchNar
  Python openyxl not updating Excel file MrBean12 1 1,938 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 1,510 Feb-07-2024, 12:24 PM
Last Post: Viento
  Search Excel File with a list of values huzzug 4 2,712 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 2,009 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Function to count words in a list up to and including Sam Oldman45 15 10,213 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 2,074 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 6,293 Feb-20-2023, 07:19 PM
Last Post: avd88
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 1,440 Feb-16-2023, 08:11 PM
Last Post: cubangt

Forum Jump:

User Panel Messages

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