Hello guys, i have this simple code. its taking tree random rows from a Excel and printing it out into a txt document.
its working well but i should do the same process with 30 excel and every time i have to choose the file... also i need to execute this code on more excel files... is there a way to automate it? like a loop or something...
its working well but i should do the same process with 30 excel and every time i have to choose the file... also i need to execute this code on more excel files... is there a way to automate it? like a loop or something...
from tkinter import filedialog import tkinter import pandas as pd import numpy as np import sys from datetime import datetime from pandas.core.indexes.base import Index from tkinter import Tk from tkinter.filedialog import askopenfilename Tk().withdraw() filename = askopenfilename() df = pd.read_excel(filename) df_new= [df.drop(columns =["note"], inplace=True), df.sample(n=3)] filename1 = datetime.now().strftime("%Y%m%d") sys.stdout = open(filename1 + '.txt', 'w') print(df_new) sys.stdout.close()