Python Tutorial: Real World Example – Parsing Names From a CSV to an HTML List

///Python Tutorial: Real World Example – Parsing Names From a CSV to an HTML List

Python Tutorial: Real World Example – Parsing Names From a CSV to an HTML List

FavoriteLoadingAdd to favorites

In this Python Programming Tutorial, we’ll be learning how to parse a CSV file and output the data to an HTML unordered list. This is a real world problem I ran into with my website. The list was becoming too large for me to maintain manually, so writing a Python script to automate this process saved me a lot of time in the future. Let’s get started.

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

source

By |2019-07-06T20:37:51+00:00July 6th, 2019|Python Video Tutorials|46 Comments

46 Comments

  1. Austin Geuke July 6, 2019 at 8:37 pm - Reply

    Thank you Corey! Your videos have been an amazing help for me. Is it possible to take each line of a csv and turn it into a separate instance of a class and assign the instance variables? My goal is to create methods and functions with the data from the csv file. Thanks again and keep up the good work!

  2. rot rose July 6, 2019 at 8:37 pm - Reply

    Every time, thank you very much. Best python channel across youtube

  3. Zein El Mokhtar July 6, 2019 at 8:37 pm - Reply

    Yes, we enjoy these tutorials. Thank you very much.

  4. Khaldun Tarabien July 6, 2019 at 8:37 pm - Reply

    Old comment but instead of break you should use continue at 10:23 so the "No Reward" line should skip and get the other names after maggie, iam sure you ment to change it but it just passed. iam learing a lot from your videos hopefull ill watch all of them. God bless you!

  5. Steven Tse July 6, 2019 at 8:37 pm - Reply

    Thankyou Corey for all of your contribution, they help me alot on learning python. on this vid, downloading offline file and upload to your website, i'm thinking is there a more fancy way such as getting the data from Patreon API if it have?

  6. Mustafa Khan July 6, 2019 at 8:37 pm - Reply

    Thank you Corey for all your amazing tutorials

  7. Prasoothan K July 6, 2019 at 8:37 pm - Reply

    I am new to Python, your videos are awesome

  8. ZXman July 6, 2019 at 8:37 pm - Reply

    I love this channel! I learn more from you than from my college professor.

  9. Deshmukh Ganesh July 6, 2019 at 8:37 pm - Reply

    loved all videos and subscribed, your explanation was best than others who say "we can learn it later, what that function does!"

  10. Andres Vodopivec July 6, 2019 at 8:37 pm - Reply

    Corey thanks so much for this real life problem example.
    Could you please do real life problems with pandas?
    Thanks

  11. Scott Wiseman July 6, 2019 at 8:37 pm - Reply

    That is a hard CSV file to parse. Have not seen the whole video. I am looking forward to see how you parse it.

  12. Joe Tang July 6, 2019 at 8:37 pm - Reply

    Magic hands. Much Much better and useful than paid classes!

  13. Hal1q July 6, 2019 at 8:37 pm - Reply

    This is great, next step, how can you get this on a HTML page?

  14. Rohit July 6, 2019 at 8:37 pm - Reply

    This video was helpful, I wanted to ask if you could make a video for making a report using python, like extraction of the the data and making report .

  15. David Alexander July 6, 2019 at 8:37 pm - Reply

    Cool video as usual. What about a csv file that is not ordered or structured with hearder but instead a continuous string that separates data with a ; delimiter. Iterating over the data returns one really long string line. Objective is to parse the string with carriage return or new line after each ;. example ( ST*834*0001*005010X220A1;BGN*00*1*20120106*010510****4;REF*38*170175;) Must regular expressions be used in combination with a csv reader or csv writer dictreader or dictwriter?

  16. Nasa Lee July 6, 2019 at 8:37 pm - Reply

    using keyword 'continue' instead of the 'break', this can be a better understanding of 'continue'.

  17. glock21guy July 6, 2019 at 8:37 pm - Reply

    Rather than using next, is there a reason not to just slice the list from the data you're reading? Like, "for line in csv_data[2:]" ?

    You're making me think pythonic 😉

  18. Flora Priyadarsini July 6, 2019 at 8:37 pm - Reply

    it is not allowing me to use 'break' after if statement.

  19. Gabriel Vasile July 6, 2019 at 8:37 pm - Reply

    Instead of using DictReader isn't it easier to use reader and make the code also readable with a codeline like fname, lname = line[0], line[1] ?

  20. Katostrofik July 6, 2019 at 8:37 pm - Reply

    Such an awesome real-world example. Thanks!
    I just used this info to do my first 'real' project that makes a list of Steam games by player count (based on achievements) since I had that CSV file handy. Can't even imagine how long it would take to enter 13281 * 2 table data cells by hand!

    http://kevinblanzy.com/secret/steam_game_list.html

  21. Ivan Stepanoff July 6, 2019 at 8:37 pm - Reply

    Great! Now i can see CVS as little homemade database for everyday tasks.

  22. kapil sharma July 6, 2019 at 8:37 pm - Reply

    please do the video on parsing reading and writing csv files also.

  23. Parth Prajapati July 6, 2019 at 8:37 pm - Reply

    i get error in this lines. names.append(f"{line[0]} {line[1]}")
    video time at 9:01 to 9:14
    Error:list index out of range.
    i am using python version 3.6.6
    In your code also i get error in same line.
    thanks for this tutorial.i really appreciate your work!!

  24. jhon jhon July 6, 2019 at 8:37 pm - Reply

    you need to make videos on python mini and advanced projects

  25. jhon jhon July 6, 2019 at 8:37 pm - Reply

    you need to make videos on python mini and advanced projects

  26. Harith Perera July 6, 2019 at 8:37 pm - Reply

    Best

  27. Mike fisvii July 6, 2019 at 8:37 pm - Reply

    do you have a video on how to automate that data to automatically update an Html page based off a time frame or schedule. That would be extemely helpful content for most everything I would want to do, if included with Json data for micro controller data logging. Thanks for the great videos, I really love your approach and thinking/teaching style. Thanks Corey for taking the time

  28. shivam kumraa July 6, 2019 at 8:37 pm - Reply

    As usual another great tutorial corey. i have a question . Now i am intermediate python programmer but i want to step up can you please suggest me some books.

  29. i18n Solutions July 6, 2019 at 8:37 pm - Reply

    Great tutorial !

  30. Not Gate July 6, 2019 at 8:37 pm - Reply

    Whole thing in 7 lines. Let me know if it can be done shorter/cleaner.

    data = pd.read_csv('patreons.csv')
    stop = data.index[data['FirstName']=='No Reward']
    names = data.iloc[1:int(*stop),[0,1]].values

    html_output = f'<p> There are currently {len(names)} contributors!</p>'
    html_output += 'n<ul>'
    html_output += ''.join([f'nt<li>{name[0]} {name[1]}</li>' for name in names])
    html_output += 'n</ul>'

  31. sandeep rawat July 6, 2019 at 8:37 pm - Reply

    Hey Corey … little help what if someone just wants to skip row 2 and row 35 only ?

  32. yuan qi July 6, 2019 at 8:37 pm - Reply

    Great tutorial

  33. steve frt July 6, 2019 at 8:37 pm - Reply

    Thanks you so much

  34. Mohammed Ismail July 6, 2019 at 8:37 pm - Reply

    Can we have videos on webscraping please

  35. MB July 6, 2019 at 8:37 pm - Reply

    Excellent tutorials. Admire your style of coding and clean and neat explanations. +1 for more of these real world examples.

  36. Patrick Freeman July 6, 2019 at 8:37 pm - Reply

    As I'm not currently on Python 3.6 yet, how would you append to names without using the f-string?
    I've tried pretty much anything from the "String Formatting – Advanced Operations for Dicts, Lists, Numbers, and Dates" video, but none of it gives a satisfactory result. What am I doing wrong? Python version is 3.5.2.

  37. Flytuts Arabic July 6, 2019 at 8:37 pm - Reply

    this was great, how to show the result on your website automatically , do you have to upload python file to your server or how it work ?

  38. Not Me July 6, 2019 at 8:37 pm - Reply

    I just discovered this channel and all I can say is that you do a great job at explaining different Python concept. Could you do a video on async/await (asnycio)? And explain what asynchronous programming really is, since so many people have problems with understanding the concept.

  39. alphastrata July 6, 2019 at 8:37 pm - Reply

    5:41 you are able to print the csv_data when parsing it through list(), when I do this i get an "I/O operation on a closed file error". python v 3.6 – what am I doing wrong? Using anaconda(IDE)

  40. Antonio Bf July 6, 2019 at 8:37 pm - Reply

    Could you make a tutorial on Tkinter? (maybe you have made one already but i cant find it)

  41. Rafael Pontes July 6, 2019 at 8:37 pm - Reply

    It's funny you posted this. I had to use this Python library recently with some data I gathered from an experiment of mine. I ended up using pandas, though. It's a nice option for data analysis/visualization and it offers functions to deal with csv files, converting them to data frames.

  42. Anthony Anonde July 6, 2019 at 8:37 pm - Reply

    OMG you are the best seriously

  43. Finney James July 6, 2019 at 8:37 pm - Reply

    Very useful video for me who does a lot of manual stuff using CSV files. Keep up the good work Corey

  44. J T July 6, 2019 at 8:37 pm - Reply

    Great video, just what I was looking for.

  45. T Pham July 6, 2019 at 8:37 pm - Reply

    You can also do a pattern match to get rid of the lines that you don't want to read in.

    pattern = "^First+"
    with open (DATAFILE, 'r') as csvfile:
    csv_data = csv.reader(csvfile)
    for line in csv_data:
    if not re.match(pattern, line) and line:

    What I have done was stored all these csv data into a sqlite3 db then queries data back from db. It's kinda handy that way.

  46. MrJarnould July 6, 2019 at 8:37 pm - Reply

    As usual, great work, Corey!
    – Jacob

Leave A Comment

*