|
发表于 2020-6-27 18:25:56
|
显示全部楼层
我也不懂了,你重新复制运行看看:
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- def dataDescribeVisualization():
- while True:
- # 读取数据
- fn = input('请输入文件名: ')
- try:
- df_mean = pd.read_excel(fn, encoding='cp936')
- df_mean_describe = df_mean.describe()
- print(type(df_mean_describe)) # <class'pandas.core.frame.DataFrame'>
- print(df_mean_describe)
- maxValue = df_mean_describe.at['max', 'atemp']
- minValue = df_mean_describe.at['min', 'atemp']
- meanValue = df_mean_describe.at['mean', 'atemp']
- # 将 atemp 进行离散化
- category = [minValue, 0.4, 0.6, 0.8, maxValue]
- labels = ['Cold', 'Cool', 'Warm', 'Hot']
- # 利用cut函数
- df['Label'] = pd.cut(df['atemp'], category, labels=labels)
- try:
- df.to_csv('bike_atemp_user_cnt_result.csv', index=False)
- print('任务四完成')
- break
- except:
- print('文件导出失败')
- except:
- print('文件名错误,请重试: ')
- dataDescribeVisualization()
复制代码 |
|