- Hands-On Data Science with Anaconda
- Dr. Yuxing Yan James Yan
- 205字
- 2021-06-25 21:08:49
Inputting data using Python
Similarly, we can use Python to retrieve the data, as shown in the code here:
import pandas as pd path="http://archive.ics.uci.edu/ml/machine-learning-databases/" dataset="iris/bezdekIris.data" inFile=path+dataset data=pd.read_csv(inFile,header=None) data.columns=["sepalLength","sepalWidth","petalLength","petalWidth","Class"]
After retrieving data, the print(data.head(2)) function can be used to see the first two instances:
> print(data.head(2))
sepalLength sepalWidth petalLength petalWidth Class 0 5.1 3.5 1.4 0.2 Iris-setosa 1 4.9 3.0 1.4 0.2 Iris-setosa
When typing pd.read.csv(), we can find the definitions of all input variables, shown in the following screenshot. Again, to save space, only the first several input variables are shown:

To prevent a future potential change in terms of a dataset link, we have a backup dataset located at the author's website, shown in the following Python code:
inFile="http://canisius.edu/~yany/data/bezdekIris.data.txt" import pandas as pd d=pd.read_csv(inFile,header=None)
The following table shows several functions included in the pandas package that we could use to retrieve data:

Table 3.4 Functions included in the Python pandas module for inputting data
To find out detailed information on each of the preceding functions, we use the help() function. For example, if we want to get more information about the read_sas() function, we issue the following commands:
import pandas as pd help(pd.read_sas)
The corresponding output, the top part only, is shown here:

- Mastering Spark for Data Science
- Windows XP中文版應(yīng)用基礎(chǔ)
- 機(jī)器人創(chuàng)新實(shí)訓(xùn)教程
- 數(shù)據(jù)挖掘方法及天體光譜挖掘技術(shù)
- ESP8266 Home Automation Projects
- 在實(shí)戰(zhàn)中成長:Windows Forms開發(fā)之路
- Excel 2007終極技巧金典
- 工業(yè)機(jī)器人實(shí)操進(jìn)階手冊
- 寒江獨(dú)釣:Windows內(nèi)核安全編程
- 工業(yè)機(jī)器人操作
- 玩轉(zhuǎn)PowerPoint
- x86/x64體系探索及編程
- 系統(tǒng)安裝、維護(hù)與數(shù)據(jù)備份技巧
- 網(wǎng)絡(luò)設(shè)備規(guī)劃、配置與管理大全(Cisco版)
- 機(jī)器人制作入門(第3版)