• Python数据分析


    Python数据分析

    \1. 环境准备
    CPython —> Jupyter —> Pandas + 周边库 —> 专业人士
    Anaconda —> CPython + conda + Jupyter + 190+库 —> 适合小白
    Miniconda —> CPython + conda —> 小白专业
    \2. 工具介绍
    PyCharm Professional Edition —> 工程化开发
    VS code / Jupyter Notebook / Jupyter Lab —> 数据科学

    \3. 安装环境
    升级pip
    ~ Windows
    python -m pip install -U --user pip
    ~ macOS
    pip install -U pip

    安装启动
    pip install jupyter
    jupyter notebook

    ​ pip install jupyterlab
    ​ jupyter lab
    ​ jupyter-lab

    \4. 三大神器
    Numpy —> ndarray
    Pandas —> Series / DataFrame / Index
    Matplotlib —> figure / subplot / plot / scatter / bar / pie / …

    a. 加载数据
    pd.read_csv —> encoding / sep / delimiter / quotechar / index_col / usecols / nrows / skiprows / iterator / chunksize
    pd.read_excel —> sheet_name / header / engine
    pd.read_sql —> SQLAlchemy —> create_engine —> Engine
    ~ MySQL:mysql+pymysql://用户名:口令@数据服务器的IP地址:端口/数据库的名字
    ~ Oracle:oracle://用户名:口令@数据库服务器的IP地址:端口
    ~ SQLServer:mssql+pyodbc://注册的ODBC数据源的名字

    ​ —> DataFrame
    ​ ~ info / head / tail
    ​ ~ set_index / reset_index / reindex / rename —> index / columns
    ​ ~ 布尔索引 / query

    b. 数据重塑
    pd.concat
    pd.merge —> left / right / how / on

    c. 数据清洗
    缺失值
    甄别:isna / isnull / notna / notnull
    处理:dropna / fillna / map / apply
    重复值
    甄别:duplicated
    处理:drop_duplicates
    Series —> unique / nunique / value_counts
    异常值
    甄别:箱线图 / 数值判定法 / Z-score判定法
    处理:drop / replace / map / apply
    预处理
    Series.str —> lower / upper / title / capitalize
    —> contains / startswith / endswith
    —> extract
    —> split
    —> replace
    .dt —> year / quarter / month / day / weekday / hour / minute
    —> days / seconds / total_seconds
    —> strftime
    Series —> map / apply
    DataFrame —> apply / transform / applymap~ 分箱(离散化)
    pd.cut(data, bins, labels)
    pd.qcut(data, [0, 0.1, 0.25, 0.5, 1])~ 虚拟变量
    pd.get_dummies()
    d. 数据分析
    获取描述性统计信息
    sum / mean / max / min / count / var / std / cumsum
    describe / skew / kurtosis
    排序和取头部值
    sort_index —> level
    sort_values —> by / ascending
    nlargest / nsmallest
    分组聚合
    groupby —> agg
    pivot_table —> index / columns / values / aggfunc
    crosstable

    e. 数据呈现
    %matplotlib inline
    %matplotlib qt —> pip install PyQt5
    %config InlineBackend.figure_format = ‘svg’

    ​ plt.rcParams[‘font.sans-serif’] = [‘中文字体名称’, ‘…’]
    ​ plt.rcParams[‘axes.unicode_minus’] = False

    ​ plot —> kind / figsize
    ​ line / bar / barh / scatter / box / pie / hist

    ​ plt.savefig / plt.show()

  • 相关阅读:
    C&C++内存管理
    发布的webservice缺少< wsdl:types/ >,< wsdl:message/ >标签
    《机器学习实战》9.树回归
    Laravel 后台管理 Dcat Admin 使用记录
    存在负权边的单源最短路径的原理和C++实现
    阿里SQL规约
    git 将本地分支与远程master主分支合并
    数字电路和模拟电路-1基础知识
    OpenCV完美实现两张图片的全景拼接(详细教程)
    计算机毕业设计选题推荐-体育赛事微信小程序/安卓APP-项目实战
  • 原文地址:https://blog.csdn.net/m0_53957045/article/details/127106526