从csv文件中读取数据
movies.csv文件中的数据
movie_id,ratting,time,director
1001,6.6,101,a1
1002,6.8,102,a2
1003,6.8,103,a3
1004,7.8,104,a4
1005,8.8,105,a5
1006,6.8,106,a6
1007,6.8,107,a7
1008,6.8,108,a8
1009,6.8,109,a9
1010,7.8,110,a10
1011,7.1,111,a11
1012,9.8,112,a12
1013,10.8,113,a13
1014,6.8,114,a14
1015,6.8,115,a15
1016,6.8,116,a16
1017,7.7,117,a17
1018,9.3,118,a18
1019,6.3,119,a19
1020,6.4,120,a20
1021,5.6,121,a21
1022,8.6,122,a22
1023,8.6,123,a23
1024,7.6,124,a24
1025,5.5,125,a25
1026,8.4,126,a26
1027,6.7,127,a27
1028,8.4,128,a28
1029,4.7,129,a29
1030,6.8,130,a30
import csv
'''
读取csv文件
'''
def read_csv_demo1():
with open("movies.csv","r",encoding="utf-8") as fp:
# reader是一个迭代器
reader = csv.reader(fp)
# next()函数是将迭代器的指针向下移动一位。此处如果不使用next()函数,读取时将包含第一行(标题行)
# next(reader)