Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introduction to pandas Exploring pandas Exploration Methods

CSV File Issues

I have followed the instructions, and for some reason cannot access the csv file. Is there something I need to download in order for it to work?

Can you get this far with the file? Are you on a Mac or PC?

import os
import pandas as pd

# We use os.path.join because Windows uses a back slash (\) to separate directories
#  while others use a forward slash (/)
users_file_name = os.path.join('data', 'users.csv')

# Open the file and print out the first 5 lines
with open(users_file_name) as lines:
    for _ in range(5):
        # The `file` object is an iterator, so just get the next line 
        print(next(lines))

1 Answer

Hey Kris,

Thanks for responding. I'm on a Mac.

I haven't had any problems with this code:

import os import pandas as pd

We use os.path.join because Windows uses a back slash () to separate directories

while others use a forward slash (/)

users_file_name = os.path.join('data', 'users.csv')

I get an error message with the next block of code:

Open the file and print out the first 5 lines

with open(users_file_name) as lines: for _ in range(5): # The file object is an iterator, so just get the next line print(next(lines))

do you have a CSV file named 'users.csv'? if not then that might be the reason for the error.