Python自学 day05 ---NumpyPandas 数据结构

2023-11-10 13:18

本文主要是介绍Python自学 day05 ---NumpyPandas 数据结构,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

同之前

先在此放一些大佬写好的总结吧~

转载自大佬:zhang_xinxiu -->【Machine learning(python篇)】-几种常用的数据结构

渔单渠 --> python--Numpy and Pandas 基本语法

以下是本菜鸟练习的笔记..

# <editor-fold desc="Numpy属性">
# import numpy as np
#
# array = np.array([[1, 2, 3],
#                 [2, 3, 4]])
# print(array)
#
# print('number of dim:', array.ndim)     # 维度
# print('shape:',array.shape)             # 行数 列数
# print('size:',array.size)               # 元素个数
# </editor-fold># <editor-fold desc="Numpy创建Array">
# import numpy as np
# a = np.array([2, 23, 4], dtype=np.int)  # 格式int,int32,int64,float32/54等
# print(a)            # 没有逗号分隔
# print(a.dtype)      # 输出格式# a = np.array([[1, 2 ,3],
#               [2, 3 ,4]])
# a0 = np.zeros((3,4))        # 生成一个全部为0的多维矩阵
# a1 = np.ones((3,4))         # 生成一个全部为1的多维矩阵
# a2 = np.arange(10, 20, 2)   # 生成range数组,起始+结束+步长
# a3 = np.arange(12).reshape((3,4))   # 生成range数组,多维化
# a4 = np.linspace(1 ,10, 20).reshape((4,5))         # 生成线段,起始+结束+段数 可重新定义形状
# print(a4)
# </editor-fold># <editor-fold desc="Numpy基础运算1">
# import numpy as np# a = np.array([10, 20, 30, 40])
# b = np.array([1, 2, 3, 4])# print(a,b)
# c1 = a-b
# print(c1)
# c2 = b**2
# print(c2)
# c3 = 10*np.tan(a)       # 三角函数
# print(c3)
# print(b<3)      # >,< ,==,!=# a = np.array([[10, 20],
#              [20, 30]])
# b = np.array([[1, 2],
#              [2, 3]])
# c = a*b     # 矩阵内对应元素相乘
# c_dot = np.dot(a,b)         # 矩阵乘法
# c_dot2 = a.dot(b)           # 矩阵乘法第二种方式
#
# print(c)
# print(c_dot)
# print(c_dot2)# a = np.random.random((2,4))     # 随机生成二行四列的值
# print(a)
# print(np.sum(a))
# print(np.sum(a,axis=1))         # 每一行中求和
# print(np.min(a))
# print(np.min(a,axis=0))         # 每一列中求最小值
# print(np.max(a))
# </editor-fold># <editor-fold desc="Numpy基础运算2">
# import numpy as np
#
# A = np.arange(2,14).reshape((3,4))
#
# print(A)
# print(np.argmin(A))         # 最小索引
# print(np.argmax(A))         # 最大索引
# print(np.mean(A))           # 平均值
# print(np.average(A))        # 平均值第二种方式
# print(np.median(A))         # 中位数
# print(np.cumsum(A))             # 前几位的累计值
# print(np.diff(A))               # 累差值
# print(np.nonzero(A))            # 非0数
# print(np.sort(A))                   # 逐行排序
# print(np.transpose(A))                  # 转向,行变列,列变行
# print((A.T).dot(A))                     # 转向并乘
# print(np.clip(A, 5, 9))                    # 小于5的变成5,大于9的变成9,5-9之间的不变
# print(np.mean(A,axis=0))                    # 每一列的平均值 axis=1 每一行
# </editor-fold># <editor-fold desc="Numpy的索引">
# import numpy as np
#
# A = np.arange(3,15).reshape((3,4))
# print(A)
# print(A[2])     # 索引第二行
# print(A[1][1])  # 索引第一行第一列
# print(A[2,1])   # 索引第二行第一列,第二种表现方法
# print(A[:,1])   # 第一列所有数
# print(A[1,1:3]) # 第一行索引的第一个到第三个索引之间的数
# for row in A:
#     print(row)      # 打印每一行
# for column in A.T:
#     print(column)   # 通过对称-》反向 打印每一列# print(A.flatten())     # 迭代输出
# for item in A.flat:
#     print(item)     # 打印每一行的数(单个值)
# </editor-fold># <editor-fold desc="Numpy 的Array合并">
# import numpy as np
#
# A = np.array([1, 1, 1])[:,np.newaxis]
# B = np.array([2, 2, 2])[:,np.newaxis]
#
# # C = np.vstack((A,B))
# # print(C)         # 上下合并
# # print(A.shape, C.shape)         # 两个序列合并成2行三列的合并
# # D = np.hstack((A,B))
# # print(D)        # 左右合并
# # print(A.shape, D.shape)
#
# # 把一个横向的序列变成竖向的序列。用Tran没用
# # print(A[:,np.newaxis])
# # A = np.array([1, 1, 1])[:,np.newaxis]
#
# C = np.concatenate((A,B,B,A),axis=0)        # 多个Array的合并 axis=0 纵向合并
# C1 = np.concatenate((A,B,B),axis=1)        # 多个Array的合并 axis=0 横向合并
# print(C1)
# </editor-fold># <editor-fold desc="Numpy 的Array分割">
# import numpy as np
#
# A = np.arange(12).reshape((3,4))
# print(A)# 只能进行等量的分割 比如4分成1,2,4部分
# print(np.split(A,2,axis=1))     # 纵向分割 分成两部分
# print(np.split(A,3,axis=0))     # 横向分割 分成三部分# 1.使用array_split 进行不等量的分割
# print(np.array_split(A,3,axis=1))# 2.使用v/hsplit方法 进行不等量的分割
# print(np.vsplit(A,3))   # 纵向分割成三块
# print(np.hsplit(A,2))   # 横向分割成两块
# </editor-fold># <editor-fold desc="Numpy的 copy 和 deepcopy">
# import numpy as np
#
# A = np.arange(4)
# print(A)
#
# # B = A       # 指针传递,B就是A
# B = A.copy()    # 把值传过去了 但是没有关联起来
# </editor-fold># <editor-fold desc="Pandas基本介绍">
# import pandas as pd
# import numpy as np# s = pd.Series([1, 3 ,6, np.NaN,44,1])
# print(s)
# dates = pd.date_range('20181104',periods=6)
# print(dates)
# df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=['a','b','c','d'])
# print(df)# 矩阵
# df1 = pd.DataFrame(np.arange(12).reshape((3,4)))
# print(df1)# 字典
# df2 = pd.DataFrame({'A' : 1.,
#                     'B' : pd.Timestamp('20130102'),
#                     'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
#                     'D' : np.array([3] * 4,dtype='int32'),
#                     'E' : pd.Categorical(["test","train","test","train"]),
#                     'F' : 'foo'})
# print(df2)
# print(df2.dtypes)           # 查看列的格式
# print(df2.index)            # 查看列的索引
# print(df2.columns)          # 查看列的名字
# print(df2.values)           # 查看值
# print(df2.describe())       # 运算数字形式的平均值 方差等数据
# print(df2.T)                # Transport 对称
# print(df2.sort_index(axis=1, ascending=False))      # 纵向(按列),倒叙排序index
# print(df2.sort_values(by='E'))                      # 对'E'这一列的值进行排序
# </editor-fold># <editor-fold desc="Pandas 选择数据">
# import pandas as pd
# import numpy as np
#
# dates = pd.date_range('20181104',periods=6)
# df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])# print(df['A'],df.A)     # 选择列
# print(df[0:3],df['20181104':'20181106'])    # 选择行# select by lable: loc          纯标签
# print(df.loc['20181105'])       # 根据标签选择 行
# print(df.loc[:,['A','B']])        # 选择所有行和指定列# select by position: iloc      纯数字
# print(df.iloc[3])               # 第三行
# print(df.iloc[3,1])             # 第三行第一列
# print(df.iloc[[1,3,5],1:3])     # 选择指定行(不连续)和列# mixed selection ix        混合上两种
# print(df.ix[:3,['A','C']])# Bollean indexing          计算检索
# print(df[df.A>8])
# </editor-fold># <editor-fold desc="Pandas 设置值">
# import pandas as pd
# import numpy as np
#
# dates = pd.date_range('20181104',periods=6)
# df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])# df.iloc[2,2] = 1111         # 根据索引修改值
# df.loc['20181103','B'] = 2222       # 根据标签改值
# df.B[df.A>4] = 0              # 根据条件改值
# df['F'] = np.NaN
# df['E'] = pd.Series([1,2,3,4,5,6],index=pd.date_range('20181104',periods=6))
# print(df)
# </editor-fold># <editor-fold desc="Pandas处理丢失数据">
# import pandas as pd
# import numpy as np
#
# dates = pd.date_range('20181104',periods=6)
# df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])
# df.iloc[0,1] = np.nan       # 假设是丢失掉的数据
# df.iloc[1,2] = np.nan# print(df.dropna(axis=0,how='any'))
# 丢掉行 axis=1:丢掉列
# 有任何一个就丢掉 how = 'any' how ='all' 全部为nan 才丢掉# print(df.fillna(value=0))       # NuN值 填充为0
# print(df.isnull())              # 返回是否缺失数据
# print(np.any(df.isnull() == True))      # 返回是否缺失数据
# </editor-fold># <editor-fold desc="Pandas 导入导出文件">
# import pandas as pd
# import numpy as np# data = pd.read_pickle('usrs_info.pickle')
# print(data)# data.to_pickle('temp.pickle')
# </editor-fold># <editor-fold desc="Pandas 合并 concat">
# import pandas as pd
# import numpy as np# concatennating
# <editor-fold desc="concat方法合并">
#定义资料集
# df1 = pd.DataFrame(np.ones((3,4))*0, columns=['a','b','c','d'])
# df2 = pd.DataFrame(np.ones((3,4))*1, columns=['a','b','c','d'])
# df3 = pd.DataFrame(np.ones((3,4))*2, columns=['a','b','c','d'])#concat纵向合并
# res = pd.concat([df1, df2, df3], axis=0)#打印结果
# print(res)
#     a    b    c    d
# 0  0.0  0.0  0.0  0.0
# 1  0.0  0.0  0.0  0.0
# 2  0.0  0.0  0.0  0.0
# 0  1.0  1.0  1.0  1.0
# 1  1.0  1.0  1.0  1.0
# 2  1.0  1.0  1.0  1.0
# 0  2.0  2.0  2.0  2.0
# 1  2.0  2.0  2.0  2.0
# 2  2.0  2.0  2.0  2.0# ignore_index(重置index)
#承上一个例子,并将index_ignore设定为True
# res = pd.concat([df1, df2, df3], axis=0, ignore_index=True)#打印结果
# print(res)
#     a    b    c    d
# 0  0.0  0.0  0.0  0.0
# 1  0.0  0.0  0.0  0.0
# 2  0.0  0.0  0.0  0.0
# 3  1.0  1.0  1.0  1.0
# 4  1.0  1.0  1.0  1.0
# 5  1.0  1.0  1.0  1.0
# 6  2.0  2.0  2.0  2.0
# 7  2.0  2.0  2.0  2.0
# 8  2.0  2.0  2.0  2.0
# </editor-fold># join,['inner','outer']
# <editor-fold desc="join方法合并">
#定义资料集
# df1 = pd.DataFrame(np.ones((3,4))*0, columns=['a','b','c','d'], index=[1,2,3])
# df2 = pd.DataFrame(np.ones((3,4))*1, columns=['b','c','d','e'], index=[2,3,4])#纵向"外"合并df1与df2
# res = pd.concat([df1, df2], axis=0, join='outer')
# inner 会裁剪掉不同的地方 只保留相同的部分# print(res)
#     a    b    c    d    e
# 1  0.0  0.0  0.0  0.0  NaN
# 2  0.0  0.0  0.0  0.0  NaN
# 3  0.0  0.0  0.0  0.0  NaN
# 2  NaN  1.0  1.0  1.0  1.0
# 3  NaN  1.0  1.0  1.0  1.0
# 4  NaN  1.0  1.0  1.0  1.0#依照`df1.index`进行横向合并, 会缺少df2的部分数据
# res = pd.concat([df1, df2], axis=1, join_axes=[df1.index])#打印结果
# print(res)
#     a    b    c    d    b    c    d    e
# 1  0.0  0.0  0.0  0.0  NaN  NaN  NaN  NaN
# 2  0.0  0.0  0.0  0.0  1.0  1.0  1.0  1.0
# 3  0.0  0.0  0.0  0.0  1.0  1.0  1.0  1.0#移除join_axes,并打印结果
# res = pd.concat([df1, df2], axis=1)
# print(res)
#     a    b    c    d    b    c    d    e
# 1  0.0  0.0  0.0  0.0  NaN  NaN  NaN  NaN
# 2  0.0  0.0  0.0  0.0  1.0  1.0  1.0  1.0
# 3  0.0  0.0  0.0  0.0  1.0  1.0  1.0  1.0
# 4  NaN  NaN  NaN  NaN  1.0  1.0  1.0  1.0
# </editor-fold># append
# <editor-fold desc="append方法合并">
#定义资料集
# df1 = pd.DataFrame(np.ones((3,4))*0, columns=['a','b','c','d'])
# df2 = pd.DataFrame(np.ones((3,4))*1, columns=['a','b','c','d'])
# df3 = pd.DataFrame(np.ones((3,4))*1, columns=['a','b','c','d'])
# s1 = pd.Series([1,2,3,4], index=['a','b','c','d'])#将df2合并到df1的下面,以及重置index,并打印出结果
# res = df1.append(df2, ignore_index=True)
# print(res)
#     a    b    c    d
# 0  0.0  0.0  0.0  0.0
# 1  0.0  0.0  0.0  0.0
# 2  0.0  0.0  0.0  0.0
# 3  1.0  1.0  1.0  1.0
# 4  1.0  1.0  1.0  1.0
# 5  1.0  1.0  1.0  1.0#合并多个df,将df2与df3合并至df1的下面,以及重置index,并打印出结果
# res = df1.append([df2, df3], ignore_index=True)
# print(res)
#     a    b    c    d
# 0  0.0  0.0  0.0  0.0
# 1  0.0  0.0  0.0  0.0
# 2  0.0  0.0  0.0  0.0
# 3  1.0  1.0  1.0  1.0
# 4  1.0  1.0  1.0  1.0
# 5  1.0  1.0  1.0  1.0
# 6  1.0  1.0  1.0  1.0
# 7  1.0  1.0  1.0  1.0
# 8  1.0  1.0  1.0  1.0#合并series,将s1合并至df1,以及重置index,并打印出结果
# res = df1.append(s1, ignore_index=True)
# print(res)
#     a    b    c    d
# 0  0.0  0.0  0.0  0.0
# 1  0.0  0.0  0.0  0.0
# 2  0.0  0.0  0.0  0.0
# 3  1.0  2.0  3.0  4.0
# </editor-fold>
# </editor-fold># <editor-fold desc="Pandas 合并 Merge">
# merge合并 利用索引合并
# import pandas as pd# <editor-fold desc="Merge">
#定义资料集并打印出
# left = pd.DataFrame({'key': ['K0', 'K1', 'K2', 'K3'],
#                              'A': ['A0', 'A1', 'A2', 'A3'],
#                              'B': ['B0', 'B1', 'B2', 'B3']})
# right = pd.DataFrame({'key': ['K0', 'K1', 'K2', 'K3'],
#                               'C': ['C0', 'C1', 'C2', 'C3'],
#                               'D': ['D0', 'D1', 'D2', 'D3']})#依据key column合并,并打印出
# res = pd.merge(left, right, on='key')
#
# print(res)# #定义资料集并打印出
# left = pd.DataFrame({'key1': ['K0', 'K0', 'K1', 'K2'],
#                       'key2': ['K0', 'K1', 'K0', 'K1'],
#                       'A': ['A0', 'A1', 'A2', 'A3'],
#                       'B': ['B0', 'B1', 'B2', 'B3']})
# right = pd.DataFrame({'key1': ['K0', 'K1', 'K1', 'K2'],
#                        'key2': ['K0', 'K0', 'K0', 'K0'],
#                        'C': ['C0', 'C1', 'C2', 'C3'],
#                        'D': ['D0', 'D1', 'D2', 'D3']})
#
# print(left)
# #    A   B key1 key2
# # 0  A0  B0   K0   K0
# # 1  A1  B1   K0   K1
# # 2  A2  B2   K1   K0
# # 3  A3  B3   K2   K1
#
# print(right)
# #    C   D key1 key2
# # 0  C0  D0   K0   K0
# # 1  C1  D1   K1   K0
# # 2  C2  D2   K1   K0
# # 3  C3  D3   K2   K0
#
# #依据key1与key2 columns进行合并,并打印出四种结果['left', 'right', 'outer', 'inner']
# res = pd.merge(left, right, on=['key1', 'key2'], how='inner')
# print(res)
# #    A   B key1 key2   C   D
# # 0  A0  B0   K0   K0  C0  D0
# # 1  A2  B2   K1   K0  C1  D1
# # 2  A2  B2   K1   K0  C2  D2
#
# res = pd.merge(left, right, on=['key1', 'key2'], how='outer')
# print(res)
# #     A    B key1 key2    C    D
# # 0   A0   B0   K0   K0   C0   D0
# # 1   A1   B1   K0   K1  NaN  NaN
# # 2   A2   B2   K1   K0   C1   D1
# # 3   A2   B2   K1   K0   C2   D2
# # 4   A3   B3   K2   K1  NaN  NaN
# # 5  NaN  NaN   K2   K0   C3   D3
#
# res = pd.merge(left, right, on=['key1', 'key2'], how='left')
# print(res)
# #    A   B key1 key2    C    D
# # 0  A0  B0   K0   K0   C0   D0
# # 1  A1  B1   K0   K1  NaN  NaN
# # 2  A2  B2   K1   K0   C1   D1
# # 3  A2  B2   K1   K0   C2   D2
# # 4  A3  B3   K2   K1  NaN  NaN
#
# res = pd.merge(left, right, on=['key1', 'key2'], how='right')
# print(res)
# #     A    B key1 key2   C   D
# # 0   A0   B0   K0   K0  C0  D0
# # 1   A2   B2   K1   K0  C1  D1
# # 2   A2   B2   K1   K0  C2  D2
# # 3  NaN  NaN   K2   K0  C3  D3
# </editor-fold># <editor-fold desc="indicator 显示自定义名">
# #定义资料集并打印出
# df1 = pd.DataFrame({'col1':[0,1], 'col_left':['a','b']})
# df2 = pd.DataFrame({'col1':[1,2,2],'col_right':[2,2,2]})
#
# print(df1)
# #   col1 col_left
# # 0     0        a
# # 1     1        b
#
# print(df2)
# #   col1  col_right
# # 0     1          2
# # 1     2          2
# # 2     2          2
#
# # 依据col1进行合并,并启用indicator=True,最后打印出
# res = pd.merge(df1, df2, on='col1', how='outer', indicator=True)
# print(res)
# #   col1 col_left  col_right      _merge
# # 0   0.0        a        NaN   left_only
# # 1   1.0        b        2.0        both
# # 2   2.0      NaN        2.0  right_only
# # 3   2.0      NaN        2.0  right_only
#
# # 自定indicator column的名称,并打印出
# res = pd.merge(df1, df2, on='col1', how='outer', indicator='indicator_column')
# print(res)
# #   col1 col_left  col_right indicator_column
# # 0   0.0        a        NaN        left_only
# # 1   1.0        b        2.0             both
# # 2   2.0      NaN        2.0       right_only
# # 3   2.0      NaN        2.0       right_only
# </editor-fold># <editor-fold desc="Index">
# #定义资料集并打印出
# left = pd.DataFrame({'A': ['A0', 'A1', 'A2'],
#                      'B': ['B0', 'B1', 'B2']},
#                      index=['K0', 'K1', 'K2'])
# right = pd.DataFrame({'C': ['C0', 'C2', 'C3'],
#                       'D': ['D0', 'D2', 'D3']},
#                      index=['K0', 'K2', 'K3'])
#
# print(left)
# #     A   B
# # K0  A0  B0
# # K1  A1  B1
# # K2  A2  B2
#
# print(right)
# #     C   D
# # K0  C0  D0
# # K2  C2  D2
# # K3  C3  D3
#
# #依据左右资料集的index进行合并,how='outer',并打印出
# res = pd.merge(left, right, left_index=True, right_index=True, how='outer')
# print(res)
# #      A    B    C    D
# # K0   A0   B0   C0   D0
# # K1   A1   B1  NaN  NaN
# # K2   A2   B2   C2   D2
# # K3  NaN  NaN   C3   D3
#
# #依据左右资料集的index进行合并,how='inner',并打印出
# res = pd.merge(left, right, left_index=True, right_index=True, how='inner')
# print(res)
# #     A   B   C   D
# # K0  A0  B0  C0  D0
# # K2  A2  B2  C2  D2
# </editor-fold># <editor-fold desc="解决overlapping的问题">
# #定义资料集
# boys = pd.DataFrame({'k': ['K0', 'K1', 'K2'], 'age': [1, 2, 3]})
# girls = pd.DataFrame({'k': ['K0', 'K0', 'K3'], 'age': [4, 5, 6]})
#
# #使用suffixes解决overlapping的问题
# res = pd.merge(boys, girls, on='k', suffixes=['_boy', '_girl'], how='inner')
# print(res)
# #    age_boy   k  age_girl
# # 0        1  K0         4
# # 1        1  K0         5
# </editor-fold>
# </editor-fold># <editor-fold desc="Pandas plot 画图">
# import pandas as pd
# import numpy as np
# import matplotlib.pyplot as plt
#
# # plot data
#
# # Series    # 线性
# # data = pd.Series(np.random.randn(1000),index=np.arange(1000))
# # data = data.cumsum()        # 累加
# # data.plot()
# # plt.show()
#
# # DataFrame # 数据点
# data = pd.DataFrame(np.random.randn(1000,4),index=np.arange(1000),columns=list('ABCD'))      # randn(1000,4)4个属性
# data = data.cumsum()
# # data.plot()     # 有很多参数可以设置
# # plot methods:
# # 'bar','hist','box','kde','area','scatter','hexbin','pie'
# ax = data.plot.scatter(x='A' ,y='B',color='DarkBlue',label='Class 1')
# data.plot.scatter(x='A',y='C',color='DarkGreen',label='Class 2',ax=ax)
# plt.show()
# </editor-fold>

 

这篇关于Python自学 day05 ---NumpyPandas 数据结构的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/382859

相关文章

Python结合PyWebView库打造跨平台桌面应用

《Python结合PyWebView库打造跨平台桌面应用》随着Web技术的发展,将HTML/CSS/JavaScript与Python结合构建桌面应用成为可能,本文将系统讲解如何使用PyWebView... 目录一、技术原理与优势分析1.1 架构原理1.2 核心优势二、开发环境搭建2.1 安装依赖2.2 验

一文详解如何在Python中从字符串中提取部分内容

《一文详解如何在Python中从字符串中提取部分内容》:本文主要介绍如何在Python中从字符串中提取部分内容的相关资料,包括使用正则表达式、Pyparsing库、AST(抽象语法树)、字符串操作... 目录前言解决方案方法一:使用正则表达式方法二:使用 Pyparsing方法三:使用 AST方法四:使用字

Python列表去重的4种核心方法与实战指南详解

《Python列表去重的4种核心方法与实战指南详解》在Python开发中,处理列表数据时经常需要去除重复元素,本文将详细介绍4种最实用的列表去重方法,有需要的小伙伴可以根据自己的需要进行选择... 目录方法1:集合(set)去重法(最快速)方法2:顺序遍历法(保持顺序)方法3:副本删除法(原地修改)方法4:

Python运行中频繁出现Restart提示的解决办法

《Python运行中频繁出现Restart提示的解决办法》在编程的世界里,遇到各种奇怪的问题是家常便饭,但是,当你的Python程序在运行过程中频繁出现“Restart”提示时,这可能不仅仅是令人头疼... 目录问题描述代码示例无限循环递归调用内存泄漏解决方案1. 检查代码逻辑无限循环递归调用内存泄漏2.

Python中判断对象是否为空的方法

《Python中判断对象是否为空的方法》在Python开发中,判断对象是否为“空”是高频操作,但看似简单的需求却暗藏玄机,从None到空容器,从零值到自定义对象的“假值”状态,不同场景下的“空”需要精... 目录一、python中的“空”值体系二、精准判定方法对比三、常见误区解析四、进阶处理技巧五、性能优化

使用Python构建一个Hexo博客发布工具

《使用Python构建一个Hexo博客发布工具》虽然Hexo的命令行工具非常强大,但对于日常的博客撰写和发布过程,我总觉得缺少一个直观的图形界面来简化操作,下面我们就来看看如何使用Python构建一个... 目录引言Hexo博客系统简介设计需求技术选择代码实现主框架界面设计核心功能实现1. 发布文章2. 加

python logging模块详解及其日志定时清理方式

《pythonlogging模块详解及其日志定时清理方式》:本文主要介绍pythonlogging模块详解及其日志定时清理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录python logging模块及日志定时清理1.创建logger对象2.logging.basicCo

Python如何自动生成环境依赖包requirements

《Python如何自动生成环境依赖包requirements》:本文主要介绍Python如何自动生成环境依赖包requirements问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录生成当前 python 环境 安装的所有依赖包1、命令2、常见问题只生成当前 项目 的所有依赖包1、

如何将Python彻底卸载的三种方法

《如何将Python彻底卸载的三种方法》通常我们在一些软件的使用上有碰壁,第一反应就是卸载重装,所以有小伙伴就问我Python怎么卸载才能彻底卸载干净,今天这篇文章,小编就来教大家如何彻底卸载Pyth... 目录软件卸载①方法:②方法:③方法:清理相关文件夹软件卸载①方法:首先,在安装python时,下

python uv包管理小结

《pythonuv包管理小结》uv是一个高性能的Python包管理工具,它不仅能够高效地处理包管理和依赖解析,还提供了对Python版本管理的支持,本文主要介绍了pythonuv包管理小结,具有一... 目录安装 uv使用 uv 管理 python 版本安装指定版本的 Python查看已安装的 Python