python pandas 文件夹数据导入 excel
下面这张图是我代码跑出来的效果https://img.alicdn.com/imgextra/i1/432465746/O1CN01eaxfB41sJiWckgVTx_!!432465746.jpg
下面是我的代码
import os
import pandas as pd
from pandas import DataFrame
import time
path1 = r'C:\Users\Administrator\Desktop\bat\1224111测试\测试'
path = r'E:\色卡保存\电子色卡\电子色卡\1\扫描文件'
excelname = r'C:\Users\Administrator\Desktop\1224.xls' # 这个改成你要读取的excel名
# path = os.getcwd() # 获取当前目录路径
df = pd.read_excel(excelname)
df.columns = ["a","b","c","d","e","f","g","h","i","j","k"]
enn = 0
cnn = 0
i = 2
for file in os.listdir(path):# 第一层文件夹
folder1_path = os.path.join(path, file)
if os.path.isdir(folder1_path):
folder1_name = file.split('.')
print(folder1_name)# 文件名
createtime = time.ctime(os.path.getctime(folder1_path))
df.loc = folder1_name
df.loc = createtime
print(createtime)
for file in os.listdir(folder1_path):# 第二层文件夹
folder2_path = os.path.join(folder1_path, file)
folder2_name = file.split('.')
print(folder2_name)
for file in os.listdir(folder2_path):
folder3_name = file.split('.')# 第三层文件夹
print(folder3_name)
if folder3_name == folder2_name:# 判断文件名
folder3_path = os.path.join(folder2_path, file)
df.loc = file.split('.')
files1 = os.listdir(folder3_path)
num1 = len(files1)
df.loc = num1
# listdir(file_path)
# print(file.split('.'))
if file.split('.') == "主图":
folder4_path = os.path.join(folder2_path, file)
folder4_name = file.split('.')
print(folder4_name)
files2 = os.listdir(folder4_path)
num2 = len(files2)
df.loc = num2
i = i + 1
DataFrame(df).to_excel('11224.xlsx', sheet_name='Sheet1', index=False, header=True)
可是我想要的效果是下面这张图
https://img.alicdn.com/imgextra/i2/432465746/O1CN01KfA7ee1sJiWfGUcBZ_!!432465746.jpg
这个要怎么改一下,我有点蒙,谢谢
页:
[1]