code
| |
| |
| |
| |
| from openpyxl import Workbook |
| from openpyxl.utils.dataframe import dataframe_to_rows |
| import pandas as pd |
| prefix = "./exp5/" |
| datafile = 'air_data.csv' |
| resultfile = 'explore_result.xls' |
| |
| |
| data_table = pd.read_csv(prefix + datafile, encoding='utf-8') |
| |
| """ Returns |
| DataFrame or TextParser |
| A comma-separated values (csv) file is returned as two-dimensional data structure with labeled axes. """ |
| df_described = data_table.describe(percentiles=[ |
| 0.75], include='all') |
| |
| |
| df_described_T = df_described.T |
| print(df_described_T) |
| ''' |
| DataFrame.count |
| Count number of non-NA/null observations. |
| |
| DataFrame.max |
| Maximum of the values in the object. |
| |
| DataFrame.min |
| Minimum of the values in the object. |
| |
| DataFrame.mean |
| Mean of the values. |
| |
| DataFrame.std |
| Standard deviation of the observations. |
| |
| DataFrame.select_dtypes |
| Subset of a DataFrame including/excluding columns based on their dtype. ''' |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| df_described_T['null'] = len(data_table)-df_described_T['count'] |
| df_described_T['standard deviation'] = data_table.std() |
| print(df_described_T) |
| ''' get the sepecified colums :(use a list contains column names) ''' |
| df_described_5 = df_described_T[['null', 'max', 'min','mean', 'std']] |
| |
| |
| df_described_5.columns = [u'空值数', u'最大值', u'最小值', u'均值',u'标准差'] |
| |
| '''这里只选取部分探索结果。 |
| describe()函数自动计算的字df = pd.DataFrame({'categorical': pd.Categorical(['d','e','f']), |
| 'numeric': [1, 2, 3], |
| 'object': ['a', 'b', 'c'] |
| })段有count(非空值数)、unique(唯一值数)、top(频数最高者)、freq(最高频数)、mean(平均值)、std(标准差)、min(最小值)、50%(中位数)、max(最大值)''' |
| |
| |
| |
| wb = Workbook() |
| ws = wb.active |
| |
| |
| for r in dataframe_to_rows(df_described_5, index=True, header=True): |
| ws.append(r) |
| wb.save(prefix+resultfile) |
| |
| |
| |
result:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2022-09-16 pythony@异常处理@try_except@catalan数和出栈排列数
2022-09-16 dataStructure_数据结构三要素/逻辑结构和物理存储结构/线性表与顺序表链表
2022-09-16 android_problems:Cannot resolve symbol