Grab Columns and Rows From Spreadsheet - Python and Excel With OpenPyXL #6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay in this video i want to start to show you how to pull out large amounts of data from your excel spreadsheet in the last video we grabbed individual cells and that's not really all that practical i mean it's cool it's a good way to get started but you're going to want to pull out a lot of data and there's a lot of different ways to do this depending on exactly what you want to do you can pull out whole columns whole rows you can pull out iterations of different columns you can pull out different ranges and we're going to look at all those things but in this video we're going to start just by grabbing a column an entire column so to do that let's go ahead and let's first comment out the stuff from the last video and now let's grab a whole column and to do this let's create a variable i'm going to call this column underscore a we want to grab all of column a and call it anything you want but it should be descriptive and in column a is what we're going to be grabbing so that's what i'll name it and here we just call the ws worksheet and again there's our brackets and inside of here we just want to call all of column a so that's really all there is to that now let's print this out onto the screen and see exactly what this is so let's go ahead and save this and come back over here and run it and you can see uh oh it's all this stuff again right so you'll notice this is a tuple and we could tell it is a python tuple which is a data type right sort of like a list and we could tell it is because it's surrounded in parentheses right here and here so in order to get the items in the tuple all of these things we need to loop through the tuple and print out each thing individually so let's do that real quick and we can use a basic for loop for that so for loop so let's go for cell in column a and column a is obviously this cell is just a variable name i invented just now in order to sort of keep track all the stuff inside of our tuple so now we can just print out cell now if we want to use an f string we can and let's wrap this whole thing in brackets and then outside of here we can put backslash n and backslash n stands for newline so this will print out each item of our tuple on its own line right that's what this n does so okay let's go ahead and save this and run it now boom it's printing them all out one at a time and it's still got this thing from the last time so we need to comment that out uh right here in fact let's just delete that so okay that's cool but it's still not that useful instead of cell we want cell dot value right it's almost always dot value when you're getting the actual value from the cell so go ahead and save this and run it one more time let me clear the screen and we do boom names john aaron sam dina josh and it's putting out a new line between each one i guess we really probably don't need that so we can if we want to take that off and in fact we don't need any of this if we're just going to call cell.value we could probably get away with that let's clear the screen yeah and it puts it on its own line by itself so we don't have to use that new line thing so okay that's all the stuff from that column now if we want to switch this all we have to do is change this to for instance column b if we save this and run it we see favorite colors blue red pink now we can do anything we want with these things we can print them onto the screen we can you know whatever we want and that's cool so this is a very sort of unsophisticated way to do this we're just going to grab everything from the column but it's sort of the first step in understanding how to pull large amounts of data out of an excel spreadsheet so that's sort of where we start we can also just do rows if we change this to one right if we save this and run it let me clear this screen we get names and favorite colors right because that is row one right we're just calling the whole row if we call seven which is merry and black but we could do that just right here boom we want to call seven save this we can run it mary and black and just that easy so that's how you grab whole columns that's how you grab whole whole rows in the next video i'll show you how to grab ranges very specific ranges and that'll be coming up in the next video
Info
Channel: Codemy.com
Views: 64,550
Rating: undefined out of 5
Keywords: python excel, python excel openpyxl, python openpyxl, python openpyxl excel, openpyxl, openpyxl python, openpyxl python excel, codemy.com, john elder, python openpyxl tutorial #6, access spreadsheet with python, use excel with python, pull column from spreadsheet with python, read excel spreadsheet with python, read excel python, access excel spreadsheet python
Id: O5rEK9uPCZA
Channel Id: undefined
Length: 4min 36sec (276 seconds)
Published: Thu Apr 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.