''' 数据的读取 ''' import pandas as pd import warnings warnings.filterwarnings('ignore') # 读取文本文件 users = pd.read_table('./users.dat', header=None, names=['UserID', 'Gender', 'Age', 'Occupation', 'Zip-code'], sep='::', engine='python') print(users.head()) # 读取csv文件 csv = pd.read_csv('./iris.csv', header=None, names=['width', 'height', 'category'], sep=',', engine='python') print(csv.head()) csv.iloc[0, 2] = 1 csv.to_csv('./iris1.csv') # 读取excel文件 excel = pd.read_excel('./data.xlsx') print(excel) 输出结果: UserID Gender Age Occupation Zip-code 0 1 F 1 10 48067 1 2 M 56 16 70072 2 3 M 25 15 55117 3 4 M 45 7 02460 4 5 M 25 20 55455 width height category 0 1.4 0.2 0 1 1.4 0.2 0 2 1.3 0.2 0 3 1.5 0.2 0 4 1.4 0.2 0 age height gender 0 21 165 M 1 22 145 M 2 23 164 M 3 24 165 M 4 25 166 F 5 26 167 F