随笔分类 - python学习
摘要:上代码: from openpyxl import load_workbookfrom datetime import datetimedef create_time(): now_year = datetime.now().year wb = load_workbook('C:/Users/adm
阅读全文
摘要:####代码如下:# 导入需要使用的模块import osimport tkinter.filedialogfn = tkinter.filedialog.askopenfilename(title='选择了一个文件',filetypes=[('文本文件','.txt'),('所有文件','.*')
阅读全文
摘要:Python操作和连接数据库 在Python中,你可以使用不同的库来操作和连接数据库,最常用的是sqlite3、MySQLdb和psycopg2。 使用sqlite3连接和操作SQLite数据库: import sqlite3# 连接数据库conn = sqlite3.connect('databa
阅读全文
摘要:import paramikodef sshExeCMD(): ssh_client=paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(ho
阅读全文
摘要:[root@zabbix-agent files]# cat xun.py# -*- coding:utf-8 -*- - import os, time last_worktime=0last_idletime=0 def get_cpu(): global last_worktime, last
阅读全文
摘要:Pandas处理数据增、删、改、查,日常使用小结,清晰版 原创 ISEE小栈 ISEE小栈 2023-07-30 19:25 发表于北京 收录于合集 #Python26个 #Pandas4个 ISEE小语 论如何判断一个人是真有钱还是装有钱? 在网上看到这样的一个回答: “穷人是小心翼翼地大方,有钱
阅读全文
摘要:上代码: # -*- coding: utf-8 -*- import difflib,webbrowserimport osimport tkinter as tkfrom tkinter import filedialog,messagebox def readfile(filename): t
阅读全文
摘要:【实用】关于Python网络运维自动化——CSV 原创 朱嘉盛 网工手艺 2023-08-04 08:05 发表于广东 收录于合集#三、运维之自动化30个 哈喽,大家好,我又来了。见字如面,每篇锤炼!近期有一篇,我介绍了JSON这种信息储存方式,【实用】关于Python网络运维自动化——JSON。该
阅读全文
摘要:Python常用的自动化小脚本,必须收藏! 原创 鬼仔 码农鬼仔 2023-08-19 18:00 发表于广东 前言 大家好,我是鬼仔。 今天给大家分享几个python常用的自动化小脚本。无论是日常生活,还是工作开发,这几个脚本都常常会用到! 1. List转JSON、String转JSON 2.
阅读全文
摘要:准备数据: ##实现成绩大于等于600为优秀,其他为普通等级 上代码: import pandas as pddf = pd.read_excel('C:/Users/Administrator/Desktop/test1.xlsx',header=1)def score_if(score): if
阅读全文
摘要:##截取身份证信息,判断身份证上面的具体信息:上代码:import redef extract_id_card_info(id_card): # 匹配身份证号码并提取出生日期和顺序号 match = re.match(r'(\d{6})(\d{4})(\d{2})(\d{2})\d{2}(\d{1}
阅读全文
摘要:准备数据 读取表头:上代码: # 导入数据处理包import pandas as pd# 读取Excel,header=1表示取第二行数据作为列名(表头)data_set = pd.read_excel('/Users/Administrator/Desktop/test.xlsx',header=
阅读全文
摘要:上代码: import csvf = open("C:/Users/Administrator/Desktop/11.txt",'r')with f: reader = csv.reader(f,delimiter=",") for row in reader: for e in row: prin
阅读全文
摘要:上代码: import csvcsvFile = open("C:/Users/Administrator/Desktop/1.csv", 'w', newline='', encoding='utf-8')writer = csv.writer(csvFile)csvRow = []f = ope
阅读全文
摘要:xlwt模块是Python中一个用于管理Excel文件的模块,用以将数据以Excel表格的形式写入到Excel文件中。它具有操作方便、支持多种Excel文件格式等优点,因此,被广泛应用于数据处理、表格导出等方面。 1. 创建Excel文件 使用xlwt模块创建并打开Excel文件: import x
阅读全文
摘要:loc 在选择时应用条件。 单条件:选择大于90成绩的学生信息: import pandas as pdsource = pd.read_excel('C:/Users/Administrator/Desktop/source.xlsx')print(source)da = source.loc[(
阅读全文
摘要:相同文件夹下合并Excel上代码:import pandas as pdimport os#文件路径file_dir = r'C:/Users/Administrator/Desktop/test/'#构建新的表格名称new_filename = file_dir + '/new_file.xlsx
阅读全文
摘要:求行的平均值代码:import pandas as pd #导入模块df=pd.read_excel(r'C:\Users\Administrator/Desktop/test/1.xlsx')#文件路径a=lambda x : x.mean(1).round(2) #lambda函数m=a(df.
阅读全文
摘要:求和,求平均import pandas as pdstudent = pd.read_excel('C:/Users/Administrator/Desktop/1.xlsx')student = student.set_index('ID')temp = student[['Test_1','Te
阅读全文
摘要:1.读取Excel数据 Python通过pandas库可以轻松地读取Excel数据。pandas库是一个专门用于数据分析和处理的库,它可以将Excel中的数据读取为DataFrame格式,便于进行后续的数据分析和操作。 import pandas as pddata = pd.read_excel(
阅读全文