【无标题】

文章目录

一、数据预处理

1、去重

python 复制代码
df = df.drop_duplicates().reset_index(drop=True)

2、删除某一列

python 复制代码
df2=df2.drop(cols,axis=1) 

3、删除两行

python 复制代码
df.drop(index=[0, 1])

4、date转字符串

python 复制代码
from datetime import datetime, date, time
d = date.fromisoformat('2018-09-22')
t = time.fromisoformat('16:28:22')
dt = datetime.fromisoformat('2018-09-22')

sdate = pd.to_datetime(ds).strftime('%Y-%m-%d')
st = "2019-01-20 00:00:00"
dt = datetime.datetime.strptime(st, '%Y-%m-%d %H:%M:%S')
st = "2019-01-20"
dt = datetime.datetime.strptime(st, '%Y-%m-%d')
start=pd.to_datetime('2017-01-01')

5、修改类型

python 复制代码
train['tf_status'] = t1['tf_status'].astype(np.int64)

6、修改日期类型

python 复制代码
df['ds'] = pd.to_datetime(df['ds'])

7、修改字段名

python 复制代码
df.rename(columns={'#studentid':'studentid'}, inplace = True)

8、加年月

python 复制代码
df['year']=df.datetime.apply(lambda x: x.year)
df['month'] = df.datetime.apply(lambda x: x.month)
df['year'] = df['year'].astype(np.int64)
df['month'] = df['month'].astype(np.int64)

9、 删除字段

df.drop('#id', axis=1, inplace=True)

10、 查看数据中顶部10%的数据

print(df.weeks.quantile(np.arange(.9,1,.01)))

11、设置索引

df = df.set_index('hetongdetailid')

12、判断空值

print("在 cat 列中总共有 %d 个空值." % df'cat'.isnull().sum())

print("在 review 列中总共有 %d 个空值." % df'review'.isnull().sum())

dfdf.isnull().values==True

df = dfpd.notnull(df\['review')]

13、排序

df.sort_values(by="x1",ascending= False)

14、 模糊查询

df_remark_tfdf_remark_tf\["content_method".str.contains(keystring)]

15、修改字段类型

df_appraise'deptid' = df_appraise'deptid'.astype(np.int64)

16、修改数据

(https://blog.csdn.net/zhangchuang601/article/details/79583551)

df.loc1,\['name','age'] = 'bb',11

df.iloc1,2 = 19#修改某一无

df.locdf\[df.htid.isin(ids).index,"y"]=1

17、保存数据库

df.to_sql(name='predict',con=mysql_engine,if_exists = 'replace')

18、生成日期

dt = datetime.datetime(year, month, 1)

19、查看顶部10%数据分布

print(movie_rating_count'totalRatingCount'.quantile(np.arange(.9,1,.01)))

二、数据可视化

#-------plotly.express-------------------------

1、折线图

import plotly.express as px

fig = px.line(df, x='date', y='y_true',

labels={'date':'日期', 'y_true':'话务量'},

markers=True)

fig.update_xaxes(tickformat = "%Y-%m-%d", hoverformat = "%Y-%m-%d")

fig.update_layout(title_text="热线部门日业务量趋势图", title_x=0.5)

fig.update_traces(marker=dict(size=3)) #控制点的大小

fig.show()

2、散点图

fig = px.scatter(df, x="真实订单量", y="真实金额",hover_data='did','日期')

fig.update_traces(marker=dict(size=4)) #点的大小

fig.show()

三、虚拟环境配置与安装

------------------更新pip命令----------------------------------------

python -m pip install --upgrade pip

如果升级失败,明明执行的就是pip升级命令,但是最后一句提示用一样的代码升级。其实是权限问题,小伙伴们按下面的代码升级即可!!!在代码后面加上 --user表示信任:

python-m pip install--upgrade pip --user

-------------搭建虚拟环境-----------------------------

1、 创建虚拟环境

conda create --name yourenvname python=3.8

2、 进入虚拟环境

conda activate yourenvname

3、退出虚拟环境

conda deactivate

4、 删除虚拟环境

conda remove -n py39 --all

5、在jupyter notebook中添加虚拟环境

python -m ipykernel install --user --name yourenvname --display-name "display-name"

6、在jupyter notebook里面添加虚拟环境

cmd进入虚拟环境(torch_env)

activate torch_env

pip install ipykernel ipython

回车

python kernel install --user --name torch_env

回车

再次进入jupyter notebook

右上角,new,即可选择需要的虚拟环境。

5.另外,如果需要在指定文件夹中打开jupyter notebook,只需要打开文件夹所在位置,点击搜索框左边的位置框,输入cmd,再输入jupyter notebook,即可将路径设为自己需要的。

在jupyter 中删除虚拟环境

jupyter kernelspec uninstall myenv

7、pip install 镜像安装

pip install package_name -i https://pypi.tuna.tsinghua.edu.cn/simple

四、其他


1、nohup command &

例如 nohup jupyter notebook &

2、找到进程PID(关闭在前面后台执行的进程的步骤,首先找到其进程PID)

ps -ef | grep xxxx

ps -ef 查看本机所有的进程;grep xxxx代表过滤找到条件xxxx的项目

3、kill掉进程

kill -9 具体的PID

-------------打开指定端口-------------------------------------

firewall-cmd --zone=public --add-port=8504/tcp --permanent

firewall-cmd --reload

netstat -ntlp //查看当前所有tcp端口·

netstat -ntulp |grep 8888 //查看所有1935端口使用情况

相关推荐
rain_sxr几秒前
大规模数据可视化渲染:D3 与 ECharts 的管线优化实战
人工智能
大海变好AI13 分钟前
AIGC分层推理落地能否串联多工具完成自动化闭环
人工智能·python·自动化·aigc
Cosolar22 分钟前
AI Agent 架构原理详解:从一次提问到任务完成的完整闭环
人工智能·后端·架构
小白说大模型23 分钟前
从向量嵌入到复杂 Agent:LLM、LangChain、LangGraph 完整科普
java·开发语言·人工智能·gpt·深度学习·langchain
协享科技29 分钟前
2026 年 AI 表格工具怎么选:ChatGPT、原生 Copilot/Gemini 与公式助手
人工智能·chatgpt·excel·copilot
geo搜搜果数据29 分钟前
实测AI搜索GEO监测工具:对比DeepSeek与豆包品牌排名差异
人工智能·langchain·embedding·搜搜果
二宝哥1 小时前
14.Python模块与包完全指南:从定义到实战
python
王莎莎1 小时前
MCP 解决的是工具接入,科研 Agent 还缺的是科学证据接口标准化
前端·人工智能
码农小白AI1 小时前
工业设备验收迈入智能审核新时代:AI报告审核通审Agent版 IACheck打造检测报告质量管控新引擎
大数据·人工智能
摸鱼师moko1 小时前
AI 来了之后,我的心流状态去哪了
人工智能·程序员