# -*- coding: utf-8 -*-
# author:baoshan import pandas as pd def main():
aqi_data = pd.read_csv('china_city_aqi_teacher.csv')
print('基本信息:')
print(aqi_data.info())
print('数据预览')
print(aqi_data.head(5)) # 基本统计
print('AQI最大值', aqi_data['AQI'].max())
print('AQI最小值', aqi_data['AQI'].min())
print('AQI均值', aqi_data['AQI'].mean()) print(aqi_data[aqi_data.City=='聊城'])
# top10
bottom10_cities = aqi_data.sort_values(by=['AQI'], ascending=False).head(10)
print('空气质量最差的十个城市')
print(bottom10_cities) # 保存csv文件
bottom10_cities.to_csv('bottom10_aqi.csv', index=False) if __name__ == '__main__':
main()
pandas操作dataframe示例,比csv模块写入csv简便了许多。