Python Forum
Sample labels from excel file in order to put them on x-axis and y-axis of a plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sample labels from excel file in order to put them on x-axis and y-axis of a plot
#9
Here's an example I ran with an excel file that I had, replace filename with one of your own and try it:
import pandas as pd
from pathlib import Path
import os

def show_incremental_rows(filename, increment):
    df = pd.read_excel(filename)
    print(df.iloc[::increment, :])


def main():
    os.chdir(os.path.abspath(os.path.dirname(__file__)))
    show_incremental_rows('GP2016Cty_637257362220392064.xls', 200)


if __name__ == '__main__':
    main()
Output:
ID Election OfficeName VoteFor BallotGroup ... CanAffilCommit County Votes PartyName PartyAbbrev 0 1 GP 2016 100TH REPRESENTATIVE 1 J ... NaN CALHOUN 525 REPUBLICAN REP 500 501 GP 2016 11TH REPUBLICAN DELEGATE 3 G ... BUSH WILL 409 REPUBLICAN REP 1000 1001 GP 2016 12TH REPUBLICAN ALTERNATE DELEGATE 3 G ... BUSH JACKSON 99 REPUBLICAN REP 1500 1501 GP 2016 12TH REPUBLICAN DELEGATE 3 G ... TRUMP WILLIAMSON 3549 REPUBLICAN REP 2000 2001 GP 2016 13TH REPUBLICAN ALTERNATE DELEGATE 3 G ... RUBIO MADISON 915 REPUBLICAN REP 2500 2501 GP 2016 14TH DEMOCRATIC DELEGATE 4 G ... CLINTON LAKE 3881 DEMOCRATIC DEM 3000 3001 GP 2016 15TH DEMOCRATIC DELEGATE 4 G ... CLINTON BOND 377 DEMOCRATIC DEM 3500 3501 GP 2016 15TH REPUBLICAN ALTERNATE DELEGATE 3 G ... CARSON EDWARDS 73 REPUBLICAN REP 4000 4001 GP 2016 15TH REPUBLICAN ALTERNATE DELEGATE 3 G ... CRUZ MOULTRIE 1091 REPUBLICAN REP 4500 4501 GP 2016 15TH REPUBLICAN DELEGATE 3 G ... PAUL RICHLAND 40 REPUBLICAN REP 5000 5001 GP 2016 16TH DEMOCRATIC DELEGATE 5 G ... SANDERS IROQUOIS 419 DEMOCRATIC DEM 5500 5501 GP 2016 16TH REPUBLICAN DELEGATE 3 G ... CARSON WINNEBAGO 435 REPUBLICAN REP 6000 6001 GP 2016 17TH DEMOCRATIC DELEGATE 6 G ... CLINTON MERCER 761 DEMOCRATIC DEM 6500 6501 GP 2016 17TH REPUBLICAN DELEGATE 3 G ... KASICH PEORIA 782 REPUBLICAN REP 7000 7001 GP 2016 18TH DEMOCRATIC DELEGATE 4 G ... SANDERS MORGAN 729 DEMOCRATIC DEM 7500 7501 GP 2016 18TH REPUBLICAN ALTERNATE DELEGATE 3 G ... FIORINA HANCOCK 16 REPUBLICAN REP 8000 8001 GP 2016 18TH REPUBLICAN DELEGATE 3 G ... KASICH MORGAN 698 REPUBLICAN REP 8500 8501 GP 2016 2ND REPUBLICAN DELEGATE 3 G ... FIORINA COOK 83 REPUBLICAN REP 9000 9001 GP 2016 57TH REPRESENTATIVE 1 J ... NaN LAKE 670 DEMOCRATIC DEM 9500 9501 GP 2016 6TH REPUBLICAN ALTERNATE DELEGATE 3 G ... CRUZ COOK 3096 REPUBLICAN REP 10000 10001 GP 2016 8TH REPUBLICAN DELEGATE 3 G ... CARSON KANE 59 REPUBLICAN REP 10500 10501 GP 2016 PRESIDENT 1 A ... NaN ADAMS 119 REPUBLICAN REP 11000 11001 GP 2016 PRESIDENT 1 A ... NaN CALHOUN 2 REPUBLICAN REP 11500 11501 GP 2016 PRESIDENT 1 A ... NaN LAKE 44823 DEMOCRATIC DEM 12000 12001 GP 2016 PRESIDENT 1 A ... NaN CRAWFORD 0 REPUBLICAN REP 12500 12501 GP 2016 UNITED STATES SENATOR 1 A ... NaN HAMILTON 62 DEMOCRATIC DEM 13000 13001 GP 2016 COMPTROLLER 1 B ... NaN LaSALLE 11592 REPUBLICAN REP
hobbyist likes this post
Reply


Messages In This Thread
RE: Sample labels from excel file in order to put them on x-axis and y-axis of a plot - by Larz60+ - Sep-12-2021, 01:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 503 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 596 Feb-07-2024, 12:24 PM
Last Post: Viento
  Search Excel File with a list of values huzzug 4 1,419 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 1,015 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  IndexError: index 10 is out of bounds for axis 0 with size 10 Mehboob 11 2,506 Sep-14-2023, 06:54 AM
Last Post: Mehboob
  matplotlib x-axis text move bottom upward jacklee26 3 1,142 May-31-2023, 04:28 AM
Last Post: jacklee26
  Print names in x-axis of a time-series values hobbyist 4 1,361 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,240 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 3,424 Feb-20-2023, 07:19 PM
Last Post: avd88
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 914 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