# import csv
# sum=0
# with open("weather.csv",'r' ,encoding='utf-8') as csvfile:
# reader= csv.reader(csvfile)
# for rows in reader:
# sum=sum+1
# print(sum) #1777行数据
# 读取第三条数据
# import csv
# with open("weather.csv","r",encoding="UTF-8") as file:
# reader = csv.reader(file)
# cols = [row for row in reader]
# print(cols[3])
# 读取前三条数据
# print("--------------")
# import pandas as pd
# data3 = pd.read_csv("weather.csv",
# usecols=['date','text','code','temperature','feels_like',
# 'pressure','humidity','visibility','wind_direction',
# 'wind_direction_degree','wind_speed','wind_scale'],nrows=3)
# print(data3)
print("---------------------")
# 读取从120条数据到140条数据(我这里显示是121行到141行)
import csv
i = 0
sum =120
with open("weather.csv","r",encoding="UTF-8") as file:
reader = csv.reader(file)
cols = [row for row in reader]
while sum<=140:
print(cols[sum])
sum+=1
i=i+1
print(i)
python读取csv文件
最新推荐文章于 2024-07-09 17:49:13 发布