Python 如何打开多个文件并将其分配给我没有的变量';以前没有定义过吗?
例如,打开3个excel文件。我想分别和3个人一起工作。但我不知道正常打开的文件数量,我怎么能做到这一点呢Python 如何打开多个文件并将其分配给我没有的变量';以前没有定义过吗?,python,python-3.x,pandas,Python,Python 3.x,Pandas,例如,打开3个excel文件。我想分别和3个人一起工作。但我不知道正常打开的文件数量,我怎么能做到这一点呢 file_path = os.path.expanduser("~/Desktop/vehıcle_report.xlsx") class load_file: def __init__(self, path): self.path = path def file_load(self): path_ad = os.p
file_path = os.path.expanduser("~/Desktop/vehıcle_report.xlsx")
class load_file:
def __init__(self, path):
self.path = path
def file_load(self):
path_ad = os.path.expanduser(self.path)
path_ex = pathlib.Path(path_ad).suffix
datac = globals()
if path_ex == '.csv':
datac = pd.read_csv(path_ad)
print('csv dosyası')
elif path_ex in ('.xlsx', '.xlw', '.xla', '.xml', '.xls'):
datac = pd.read_excel(path_ad)
else:
break
将它们放在列表中。一旦你完成了
pd.read\u csv
你就创建了一个pandas
数据框架。该文件已不再打开或正在使用。与任何其他Python对象一样,datac
可以放入列表或其他合适的结构中。不要吝啬于基本的Python学习。非常感谢。你给了我新的视角。我会多工作。