Как загрузить файл csv в jupiter notebook
Перейти к содержимому

Как загрузить файл csv в jupiter notebook

Как загрузить файл CSV в Jupyter Notebook?

Я новичок и изучаю машинное обучение. Я наткнулся на учебник, который нашел в Интернете, и хотел бы, чтобы программа работала, чтобы лучше понять. Однако у меня возникают проблемы с загрузкой CSV-файла в Jupyter Notebook.

Я получаю такую ​​ошибку:

а вот код: введите описание изображения здесь

Я следил за онлайн-инструкциями по этой ошибке, но ни один из них не работал. Кто-нибудь знает как исправить?

3-я попытка с r «путь» введите описание изображения здесь

Я пробовал также «\» и utf-8, но ни один из них не работал.

Я использую последнюю версию Anaconda Windows 7 Python 3.7

Используйте необработанную строковую нотацию для пути к Windows. В питоне ‘\’ имеет значение в питоне. Вместо этого попробуйте сделать строку, подобную этой r «path»:

student_data = pd.read_csv(r»C:\Users\xxxx\Desktop\student-intervention- system\student-data.csv»)

Если не работает, попробуйте так:

Either replace all backslashes \ with frontslashes / or place a r before your filepath string to avoid this error. It is not a matter of your folder name being too long.

Как упомянул Богун Мелецки, \ символ, который обычно используется для обозначения файловой структуры в Windows, имеет другую функцию при написании внутри строки.

From Python3 Documentation: The backslash \ character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

Как это особенно влияет на ваше утверждение, так это то, что в строке

\Users совпадает с escape-последовательностью, \Uxxxxxxxx посредством которой xxxxxxxx ссылается на a Character with 32-bit hex value xxxxxxxx . Из-за этого Python пытается найти 32-битное шестнадцатеричное значение. Однако, поскольку -sers from Users не соответствует xxxxxxxx формату, вы получите сообщение об ошибке:

SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape

Причина, по которой ваш код работает сейчас, заключается в том, что вы поместили r перед ‘C:\Users\xxxx\Desktop\project\student-data.csv’ . Это говорит python не обрабатывать символ обратной косой черты, / как обычно, и читать всю строку как есть.

Надеюсь, это поможет вам лучше понять вашу проблему. Если вам нужны дополнительные разъяснения, дайте мне знать.

4 ways to load data in Jupyter notebook and visual studio code.

How to load a dataset from a csv file from your local computer to Jupyter Notebook or Visual Studio for data analysis using python and pandas.

There are 2 primary ways to accomplish this

Option 1: Load CSV File from local computer in jupyter notebook and visual studio code using python and pandas

Put the dataset in the same folder you are working with and load the data from there

Step 1: Copy the dataset into the same folder containing your notebook.

Step 2: Import pandas

Step 3: Use this line of code to load the data located in the same folder you are currently working in.

Step 4: Verify that the data is loaded correctly by using data.head().

GRAB MY FREE DATA SCIENCE RESOURCES

  • FREE Data Science Job and Career Resources
  • FREE Data Science Books
  • FREE Data Science Cheat Sheets
  • FREE Data Science Tutorial Python Notebooks, Videos, and Podcast.
  • Get the CODE to EVERY data science tutorial on this website.
  • Get the Python Notebook used in this blog post
Option 2: Load CSV File from local computer in jupyter notebook and visual studio code with python and pandas using local file path

The first step is to copy the file path/location of the dataset csv file you want to use for data analysis

How you do this on mac is a little bit different, but all the same concepts apply. This is how you do it in windows.

Step 1: Import pandas in your notebook.

Step 2: Locate the csv file you are trying to import

Step 3: Select the file –> Click on Home –> Click on Copy file path.

Step 4: Use the file path to read the CSV file. If you put in the raw file path, your notebook or visual studio code might throw an error. So, make sure to put “r” before the file path to convert the file path you copied into a regular string. This is how you do it.

Step 5: Verify that the data is loaded correctly by using data2.head().

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *