1,读取python中的第一层的文件夹和第二层的文件夹
import os
import json
path="/home/SENSETIME/huangweijie2/PycharmProjects/AUTODRIVE-7644_get_diff_map_node_score_ab2a7f4_2021_03_15_21_48_15"
def get_sub_dirs(root_path):
root_depth = len(root_path.split(os.path.sep))
firt_lever=[]
folder_name=[]
for root, dirs, files in os.walk(root_path, topdown=True):
for name in dirs:
dir_path = os.path.join(root, name)
dir_depth = len(dir_path.split(os.path.sep))
if dir_depth == root_depth + 1:
firt_lever.append(dir_path)
folder_name.append(name)
else:
break
return firt_lever,folder_name
json_name="evaluation_result.json"
first,folders=get_sub_dirs(path)
for folder in folders:
print(folder)
2,导出的excel表格根据内容设置表的高度和宽度
表格读取
自适应列宽
表格格式处理
3,txt中每行有多个txt的时候,使用numpy直接读取就可以了
a=np.loadtxt(txt_name)
4,python画出分位图
import matplotlib.pyplot as plt
fig = plt.figure() # 创建画布
ax = plt.subplot() # 创建作图区域
# 蓝色矩形的红线:50%分位点是4.5,上边沿:25%分位点是2.25,下边沿:75%分位点是6.75
ax.boxplot([range(5), range(10), range(20)])
plt.show()
5,多个文件时候的操作
import pandas
import glob
for r in glob.glob("test*.csv"):
csv=pandas.read_csv(r)
csv.to_csv("test.txt",mode="a+")
6,批量的更换文件的后缀名
def rename_type_as_json(path, type='.json'):
filelist = os.listdir(path)
for files in filelist:
olddir = os.path.join(path, files)
if os.path.isdir(olddir):
continue
filename = os.path.splitext(files)[0]
filetype = os.path.splitext(files)[1]
newdir = os.path.join(path, filename + type)
os.rename(olddir, newdir)
return