- 博客(7)
- 收藏
- 关注
原创 pandas 修改dataframe指定区域的数值
m、n分别为目标区域左上角元素的行列坐标,这行代码将df中一个2×2的区域的值修改成‘001’
2023-08-21 15:12:16
160
1
原创 dataframe 根据A列对B列去重
我有两列数据,其中A列有一些重复的值,想要使A列是重复值的行的对应B列值为0如图,使A列首次出现的值所对应的B列保持原值,A列重复出现的值所对应的B列值为0(使第3行和第5行的的B为0)df_series=data['A'].duplicated(keep='first') data['df_series']=df_series #如果A列为重复值就会为True#data['df_...
2021-07-05 13:57:38
499
原创 dataframe使用groupby函数,根据某几列的值分组,对另一列进行计算/count
有这样一个csv表格根据A、B列分组,对C列进行求和:Result=df.groupby(['A','B'])[['D']].sum()得到的结果也是一个dataframe:(最底下的那行是求和过的)同理,根据A、B列分组,对C列进行计数:Result=df.groupby(['A','B'])[['D']].count()得到的结果:现在A和B都成了索引,可以用Result['hg']访问数据...
2021-06-29 16:02:07
5600
原创 sql 语句 选择某列为最大值或最小值时所在的行
选择A列里最大值所在的行select * from table where A=(select max(A) from table)
2021-06-29 13:52:34
3471
1
原创 python 返回当前星期数
from datetime import date,timedeltatoday = date.today()ww=today.strftime('%Y%U')https://m.runoob.com/python/att-time-strftime.html
2021-06-29 13:44:36
213
原创 python 脚本在crontab里无法执行,但该脚本手动可以运行
解决方法:建立一个shell文件,设置python执行的绝对路径,在shell文件里执行python文件,再在crontab里执行crontab定时任务vim test.sh. ~/.bash_profilePYTHON3=/u/pareng/bin/python3$PYTHON3 ~/test1.pycrontab -e00 18 * * 5 . /etc/profile;/bin/sh test.sh #每周五18:00执行...
2021-06-29 13:31:56
373
原创 python 连接SQL数据库,读取内容到dataframe,使用fetch函数查询获得返回值
from sqlalchemy import create_engineimport pymysqlimport pandascon = pymysql.connect(host='**',user='**',password='**',database='**',port=**,charset='utf8')cur=con.cursor()data=cur.execute('select * from table') #执行sql语句data=cur.fetch...
2021-06-29 13:30:36
619
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人