import docx
import pandas as pd
import os
path = r'/Users/Minute/Downloads/XX直营门店/XX直营门店-广东-37'
list1 = []
list2 = []
list3 = []
list4 = []
list5 = []
list6 = []
list7 = []
list8 = []
list9 = []
list10 = []
list11 = []
list12 = []
list13 = []
list14 = []
for root, dirs, files in os.walk(path):
for file in files:
file_path = os.path.join(root, file)
if file_path.split('.')[1] == 'docx':
file_path1 = file_path
list1.append(file_path1)
document = docx.Document(file_path1)
table = document.tables
list2.append(table[0].cell(3, 2).text.replace(',', ''))
list3.append(table[0].cell(3, 2).text.replace(',', ''))
list4.append(table[0].cell(10, 6).text.replace(',', ''))
list5.append(table[0].cell(12, 6).text.replace(',', ''))
list6.append(table[0].cell(7, 9).text.replace(',', ''))
list7.append(table[0].cell(7, 9).text.replace(',', ''))
list8.append(table[0].cell(4, 9).text.replace('注册地址:', '').replace('\n联系地址:同注册地址', '').replace(',', ''))
list9.append(table[0].cell(4, 9).text.replace('注册地址:', '').replace('\n联系地址:同注册地址', '').replace(',', ''))
list10.append(table[0].cell(20, 6).text.replace(',', ''))
list11.append(table[0].cell(20, 12).text.replace(',', ''))
list12.append(table[0].cell(23, 9).text.replace(',', ''))
list13.append(table[0].cell(22, 9).text.replace(',', ''))
list14.append(table[0].cell(21, 9).text.replace(',', ''))
data = pd.DataFrame(index=[list2, list3, list4,
list5, list6, list7, list8, list9, list10, list11, list12, list13, list14])
data.to_csv(r'/Users/Minute/Downloads/广东合并数值-列.csv')
print(data)
你的大致目的是将数据列中的逗号替换为空么,
如果是的话,其实可以先将数据提取出来,然后再做处理,因为看不到你的源数据,所以不确定你是在处理什么东西,把数据贴一份来看看