- Learning Data Mining with Python(Second Edition)
- Robert Layton
- 197字
- 2021-07-02 23:40:12
Loading with pandas
The MovieLens dataset is in a good shape; however, there are some changes from the default options in pandas.read_csv that we need to make. To start with, the data is separated by tabs, not commas. Next, there is no heading line. This means the first line in the file is actually data and we need to manually set the column names.
When loading the file, we set the delimiter parameter to the tab character, tell pandas not to read the first row as the header (with header=None) and to set the column names with given values. Let's look at the following code:
all_ratings = pd.read_csv(ratings_filename, delimiter="t", header=None, names
= ["UserID", "MovieID", "Rating", "Datetime"])
While we won't use it in this chapter, you can properly parse the date timestamp using the following line. Dates for reviews can be an important feature in recommendation prediction, as movies that are rated together often have more similar rankings than movies ranked separately. Accounting for this can improve models significantly.
all_ratings["Datetime"] = pd.to_datetime(all_ratings['Datetime'], unit='s')
You can view the first few records by running the following in a new cell:
all_ratings.head()
The result will come out looking something like this:

- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- 我的第一本算法書
- NativeScript for Angular Mobile Development
- Mastering OpenCV 4
- Python Network Programming Cookbook(Second Edition)
- 正則表達(dá)式經(jīng)典實(shí)例(第2版)
- Visual C++數(shù)字圖像處理技術(shù)詳解
- Big Data Analytics
- Python機(jī)器學(xué)習(xí):手把手教你掌握150個(gè)精彩案例(微課視頻版)
- Python:Master the Art of Design Patterns
- Learning Python by Building Games
- 響應(yīng)式架構(gòu):消息模式Actor實(shí)現(xiàn)與Scala、Akka應(yīng)用集成
- Java程序員面試筆試寶典(第2版)
- OpenCV with Python By Example
- Scratch·愛(ài)編程的藝術(shù)家