Skip to main content

Importing the Dataset in Python

    That is how to import data from csv file in Python.
import pandas as pd
dataset = pd.read_csv('Data.csv')
    It will create a data frame and it will contain exactly the same rows and columns and values from file Data.csv. We will use library pandas which we gave it the shortcut named pd.
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
    We call x for the matrix of features and y for the dependent variable vector. First we will get data from dataset so I am adding a dot after dataset to use pandas's data frame "iloc". We can specify the rows that we want to get and put into x. And the trick to take all the rows whatever dataset you have with whatever number of rows is to add a ":". Because a colon in python means a range and when we specify a range without the lower bound and neither the upper bound that means in Python that we are taking everything in the range.
    We have to specify which columns want to select with the indexes and to separate he rows that we just took from the columns we need here to add a comma. Add a new range here which this time will be colon minus one. Because colon here means the range. We are taking a range here on the left we have nothing that means that we are taking the first index in the index 0 because index in Python started from 0 and then we are going up to minus one. Because the last column in Python means the index of the last column. It will take all the columns excluding the last one.
    In order to finish this line of code, we add dot values and this means that we are taking indeed all the values in all the rows of this dataset and all columns except the last column.
    In y, we only want to get the last column. We definitely don't want to get a range. Minus one is exactly the index of the last column.
The last you can check the data which you import from Data.csv to x and y by
print(x)
print(y)

Comments

Popular Posts

Hướng dẫn sửa lỗi "File is changed: W[2007] L[2]" Đột Kích

Đây là lỗi game rất nhiều người (trong đó có mình mắc phải). Tuy nhiên khi lên diễn đàn hỏi thì các MOD đều trả lời 1 câu là tải game về cài lại rồi close luôn topic. Mình rất không hài lòng về điều đó. Hình ảnh ví dụ về lỗi : Và dưới đây là cách mình sửa. Tải trên mạng File bị lỗi (Có ghi tên file khi CF thông báo lỗi) hoặc copy từ máy tính khác về. Replace vào thư mục của nó. Vậy là ok. Các bạn nào hỏng file nào thì tải về rồi replace nó. Nếu ko có thì comment ở dưới, mình sẽ upload sớm nhất có thể cho các bạn. Video hướng dẫn :

Vì sao nên chơi LOL server NA (Bắc Mĩ)

Dưới đây là những lí do mình khuyên bạn nên chơi Liên minh server Bắc Mỹ : 1. Giá 1 số tướng rẻ hơn server VN 2. Chế độ chọn tướng, chọn vị trí rồi mới chọn đội 3. Quà tặng cho tân thủ nhiều hơn (Tristana (tướng + skin) + Alistar (tướng + skin)) 4. Nhiều icon cho bạn lựa chọn 5. Số lượng gói combo nhiều hơn 6. Có thể chuyển tài khoản đến các vùng khác trên thế giới  7. Có thể hoàn lại những vật phẩm đã mua (Cả bằng IP lẫn RP) 8. Trình độ bên đó cao hơn hẳn server VN và ko có trẻ trâu, cãi nhau rất ít. Hướng dẫn chuyển server VN sang NA :  http://ngdinhnha.blogspot.com/2014/04/chia-se-huong-dan-choi-lol-tat-ca.html Tải game tại :  https://signup.leagueoflegends.com/en/signup/redownload Đăng kí  tài khoản LOL NA tại :  https://signup.leagueoflegends.com/en/signup/index

How to play League of Legends server Japan Closed Beta - Testing account

The first, you need League of Legends by Riot. (Here, I am playing in server North America) Download Next, Click to  North America. Then, Click to North America. Then, Click Japan And Save Waiting for download Japanese version. League of Legends server Japan Closed Beta is starting from February 4th. This is testing account :  Good luck ! Video :