Question

In: Computer Science

Python Script: Question: Please edit my script for it to get to the right directory and/or...

Python Script:

Question: Please edit my script for it to get to the right directory and/or folder. How to get the right files in the folder to display under files. I don't want anymore errors. Thanks-

#Program to combine multiple excel file into one master file/spreadsheet

#import library

import os
import pandas as pd
cwd = os.path.abspath(")
files = os.listdir(cwd)

#Combine multiple excel files
#This blocks of code will loop through files in directory/folder and append/merge .xlsx files

df = pd.DataFrame()
for file in files:
   if file.endswith('.xlsx'):
       df = df.append(pd.read_excel(file),ignore_index=True

#Display first 5 rows of data/records
df.head()

#Display total columns and rows
df.shape()

df.to_excel('Output.xlsx')

Solutions

Expert Solution

To get your current working directory path

  • Navigate to your folder and type pwd.
  • Note that all xsls files should have same header which column are to be appended else we end up having a new column for every new column.

Code

import os
import pandas as pd

#change this to your actual path this was mine
path = os.path.abspath("/home/geek/Downloads/SHEETS")
files = os.listdir(path)


dataframe = pd.DataFrame()
for file in files:
    if (file.endswith('.xlsx')):
        dataframe = dataframe.append(pd.read_excel(file),ignore_index=True)
                    
#Display first 5 rows
print(dataframe.head())

#Display total columns and rows
print(dataframe.shape)

dataframe.to_excel('Output1.xlsx',index=False)

Screenshots

Input Sheets

Output


Related Solutions

Please, I need to get this right. No one is yet to get it right, it...
Please, I need to get this right. No one is yet to get it right, it has been answered on Chegg but is wrong In a psychrometric process, Volume of a classroom = 300 m^3. and temperature in the room is T= 20 oC, P=100 kPa relative humidity = 50% if all the water vapor of air in the room is converted to liquid at the same temperature, what is the volume of the liquid water (mL). I believe the...
Please fix this python script, I keep getting a return outside function error and cannot get...
Please fix this python script, I keep getting a return outside function error and cannot get it to run: def caesar(plainText, shift):     cipherText = "" for char in plainText:     newChar = ord(char) + shift     if newChar > 128:       newChar = newChar % 128     finalChar = chr(newChar)     cipherText += finalChar return cipherText text = input("Enter a message: "); s = input("Enter the distance value: "); print (caesar(text, int(s)));
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
use repil.it edit my code please i already did all part but need to edit more...
use repil.it edit my code please i already did all part but need to edit more its run for some not shwing all intro to C-programin be sure to edit on my code very basic and add good comments thank you 1-Write a program that requests 5 integers from the user and stores them in an array. You may do this with either a for loop OR by getting a string from stdin and using sscanf to store formatted input...
Write a script that prompts the user for a pathname of a file or directory and...
Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).
my question is in python. My question is how to add post users to post gres...
my question is in python. My question is how to add post users to post gres in python
Please edit, rephrase or add something to the following part of my report. Question:Whether debt funding...
Please edit, rephrase or add something to the following part of my report. Question:Whether debt funding would be desirable, or even possible for the new equipment required should the company decide to pursue aggressive expansion – noting that the equipment used by the business is quite specialised and cannot easily be sold and taken to another company. Answer:Debt funding is not adviseable as these assets are specialised and resale would not be easy .An Operating lease option would be preferred...
Write a script in C that will do the following : 1. Create the directory ZHW3....
Write a script in C that will do the following : 1. Create the directory ZHW3. 2. Verify that the directory is created by display all information related to the directory and not just the name of the directory. 3. Assume that the input from the command is used to validate password strength. Here are a few assumptions for the password string. • Length – minimum of 8 characters. • Contain alphabets , numbers , and @ # $ %...
(python please) The Cache Directory (Hash Table):The class Cache()is the data structure you will use to...
(python please) The Cache Directory (Hash Table):The class Cache()is the data structure you will use to store the three other caches (L1, L2, L3). It stores anarray of 3 CacheLists, which are the linked list implementations of the cache (which will be explained later). Each CacheList has been already initialized to a size of 200. Do not change this. There are 3 functions you must implement yourself: •def hashFunc(self, contentHeader)oThis function determines which cache level your content should go in....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT