Python: Deleting Files with a Specific Extension

Very few things in life come close to the satisfaction that I get when closing out a project and deleting old files. I have been working on automating the deletion of some of my files and here is a quick cleanup python script that you can use too.

First, open your PowerShell or notebook, whichever you are comfortable working in. Then determine where the files that you want to delete are located, and determine if they are a specific type of file you want to delete. Now that you have an essential plan you can begin.

You will need to import a python package that identifies paths on your computer. The package is called Path, and you can pip install it by typing pip install if you do not have it already. One thing I noted is that in some versions of python path you can use a lower case p. I am using Python3 and need to use an uppercase P.

Then you will need to define the location of the files that you are deleting. Here, I chose to define my function as d but you can call yours whatever you want. Then you will need to list the directory information where your files are located with your specific information. One thing to remember here is make sure you have your opening and closing quotes! I forgot that the first time I was trying this out.

d = Path('C:/Users/name/Desktop/Test_folder/')

Next, apply the method walkfiles to your path d.   For reference, the walk() method comes from the path  package and is able to generate file names in the tree directory on your computer. The purpose of applying this with the astrisk is that you are looking at all types of files. I like to then use a list to show all the files in the folder.

walkfiles list

From there, I created a variable named files and assign it the method of walkfiles and only want to delete Excel files.

defining files

Then you will create a For Loop, which means python will process each line of and end with the print option. What the text is saying is in the files that are defined with the extension of .xsls, you are applying the remove method. Printing the files with the Excel extension will show that the correct things have been deleted.


Hope you enjoyed this quick script on deleting. Remember that if you implement this it will delete your files and not simply put them into your trash can!

Follow by Email
Continue Reading

Analysis: Pivot Tables

I have been playing around with the pivot_table function in the Python package, pandas.  The reason for this is because I was using groupby and wanted to see the difference in functionality and how it could impact my work.

Using the pivot_table function is a lot like PivotTables that you may have used or seen in Excel where you can reshape data and quickly apply indexes and columns to perform analysis.  One thing to note before starting is that pivot_table is one  Python function that is constructed of arguments and lists. pivot_table is just one way to do analysis on data which I find to be the fun part in learning.

In my example, I explored pivot_table through a fictitious data set on gift officer data.  This sample only scrapes the surface of this function but I hope you enjoy!

Questions that directed my experimentation with pivot_table.

  1. How many gift officers are in this sample?
  2. How can I see who is assigned to each manager?
  3. How do I aggregate information for each manager?
  4. How do I filter on specific information, like accepted proposals>?


As I started up my project, I loaded in my DataFrame and reviewed all the data.


After looking at my data, I wanted to see how many managers were actually in the file. To start looking at manager information, I identified my index to be Manager data. Note that in this section, Ask columns look strange and do not total the correct amounts.  Also note that the table is created referencing the DataFrame (df), and the function is under the pandas namespace and so begins with pd., rather than being a method of a DataFrame (like df.groupby).  Due to muscle memory, I make the mistake of beginning to type df.pivot_table.


My next step was to then look at the ID information to see what IDs were linked to specific managers.  This helps me see that record 4413 has worked with three of the four managers in the sample.  The actual values in the data set are incorrect because the default of pivot_table is to report the mean. The returned value can be specified to return sums and lengths.


My next step was to add in Columns, or the section that data is compared.  I specified the column to be Status while keeping the index the same. As you can see, this yielded an error because Status does not contain numeric data.  The important thing here to remember is that errors are normal, especially when you are practicing new skills or constructing your argument differently.  The great thing about errors is that you can learn why they occur and how to modify your code.errorerror2


Still wanting to check out the Status and learning that only numeric data can be applied to the columns, I rearranged my variables and added Ask_Amount, Actual_Ask and Accepted_Ask.  Note here that in the output, the columns are arranged alphabetically.


After looking at the last table, I determined that I did not care to see the IDs anymore in the data.  That was because I felt that I did not need to know information on a record by record level, but rather in aggregate.  To show the sum for each manager I applied the argument aggfunc and set the value to return the sum.  What a world a a difference that makes, huh?


My final thought in working through this data set was about filtering.  What if I wanted to filter on a specific value such as accepted ask amounts only?  My first step was define a new set of data.  I did that by making a variable called Officer_table.  You will see that all the code after the equals sign is the pivot_table function previously used before. Then I used .query and specified that I only want look ask information if the Status was Accepted.  To do that I used the operator ==, make sure you check out other Boolean operations and comparisons if you want to get into specifying data in your work.



Hope you enjoyed this quick overview of pivot_table!  You can learn more about them  in the pandas documentation.



Follow by Email
Continue Reading

Xbox 360 Wireless Controller Teardown

I’ll be honest, I did a teardown last week of a cheap tower fan and was so grossed out by the dust and felt duped by poor documentation that I didn’t post.  So I turned around and took apart a disgusting Xbox 360 wireless controller.  This teardown had a lot of me saying, “nerds…spilling soda on their controller and mucking up the buttons” while I was researching Microsoft processors and understanding the irony of my statement.

 Tools Needed:

  • Xbox Wireless 360 controller (wired will do just fine)
  • Torx Security bit / tamper-resistent torx : T8 (I used the iFixit 54 Bit Driver Kit for this bit)
  • Phillips bit: PH00
  • Spudger
  • Small bowl or container for screws
  • Rubbing Alcohol, Isopropyl spray (alcohol spray), air duster


When you come into possession of a Xbox 360 wireless controller that you want to tear apart or modify, I recommend cleaning as much of the casing as possible.  Then flip the controller over so directional pad (d pad), buttons, thumbsticks face downward.  Pop out the batteries, or rechargable battery and locate the torx security screws.  I’ll give you a hint, there is one located under the serial sticker, so you can pull up the edge and use your fingers or a set of tweezers to remove the sticker about halfway.



The torx screws in this teardown are a little bit different then what you saw in the Fitbit Charge HR.  The torx security, or tamper-resistant torx screw has a post in the middle.

Torx Screw 

torx screw

Security Torx Screw



Once you remove all 7 of the screws the casing will need to be removed.  I took the spudger to pop up the sides.  After loosening up the sides, I gripped the headphone  port and the charging port and easily took of the back housing. I will note, you should ground yourself here – this is an electronic.


Once that is removed you get a full view of the circuit board.  First things first – you see two weighted metal things with wires. Those are the rumble packs that provide tactile feedback when you’re playing and are 2 speed motors. One thing to note is that the right rumble pack has a much larger weight then the left.  The reason for that could be a way for the game to send a little feedback, and then more feedback.  So imagine you are playing a racing game and you drive on the grass – you get a little feedback.  Then you continue to drive into a wall, you get a lot of feedback with both the motors. What is funny is these motors compared to the Fitbit vibrating motor.  Both are so powerful!rumble_pack


Throw back to the Fitbit teardown


You can disconnect the motors by pulling out the white circuit.  You may have to pull a bit but you likely will not break the wires.



Then you will see this huge Microsoft Processor X810462-003.  Because of the proprietary nature of Microsoft, I can’t actually determine what this processor does, but I imagine this primarily deals with the incoming and out going data and helps the Xbox understand what buttons are being selected and if feedback needs to occur.  What I think is really cool here is thinking about how quickly all of this information is processed that the end user hardly notices any delay!

To the right of the processor there is a oval shaped silver piece sticking up.  That is the RF Crystal oscillator.  What that means is the piece is a radio frequency oscillator that is designed to make the motors shake.


Flipping the circuit board over what is notable is the different grounds from all of the keys.  You can easily spot the Y,X,B,A buttons as well as the start, back, and Xbox button.  You can also see all the spots of contact that need to be hit when button mashing.


Then you will see the two thumbsticks.  You can pop those right off and give ’em a good cleaning.  From there, you can see that the stick rotates in 2 main directions and can even click.  What is interesting to me is that the button is held down my copper, but does not conduct electricity.


If you are so inclined, you can take apart the directional pad (d pad) but it is really two bits of plastic.

Once you have cleared everything, reassembly is fairly easy and you can definitely touch things and reassemble to make the controller work again.


Hope you enjoyed this teardown.  I’ll keep looking for things with less priorietary information as learning is more fun when parts can be researched!

Follow by Email
Continue Reading

Cabin Filter Replacement, A Glovebox Teardown


I purchased my car with settlement money after getting hit by a car on my bicycle and being knocked out in the middle of the road covered in safety glass.  I still generally don’t like driving in DC but have come to terms that going home to Minnesota is much easier with a car, as are trips to IKEA, and delicious Korean barbecue restaurants in Virginia.  With that said, I’ve kept my little blood money car and do general maintenance on it with regularity.

After a recent maintenance appointment the mechanic told me I needed to change my cabin filter and the cost was about $70  because the filter was behind the glove box.  I was also told that the cabin filter was not the most critical thing to repair right away so I could think about scheduling my appointment.

After chewing on that price and thinking about how it would take me 2 hours to simply drop-off and pick-up my car at the mechanic I did some Googling and found that indeed, the cabin filter is behind the glove box, but it is also possible to change it yourself.*  So of course I thought that taking apart my most valuable possession was a great idea in spite  of having little to no car knowledge.

Tools Needed:


Please note, taking photos of the car was a lot trickier than I thought, so some of these images are renderings from Nissan and are more accurate.


Locate four screws on the on bottom of the glove box and remove them one by one. The image above is a shop of the bottom screws, so you can see they are fairly big and easy to see. You will need to be kneeling on the ground or perched strangely in your car to do this so I advise wearing pants or padding your knees if you have bare legs.


Open the glove box.  There are two  screws by the latch and one screw on each corner of the top (the drawing above shows the two in the middle and on the sides).  Unscrew carefully and one by one – it doesn’t matter the order and you do not need to loosen all of them first.

While I was doing this I kept saying “what if this thing falls on my head? What if I do something and have to drive back to the mechanic without my glove box?” Seriously, do not worry about car parts falling on your head or not being able to get the box back in – I did it and you can too!

After removing all the screws, put your hand on the top part of the glove box and slowly pull out. When removing, you the glove box you will see that there is a light attached in the middle.  Remove the light by twisting left and it should pop right out.  Place glove box in the backseat of the car or on the ground.


After you remove the glove box, the filter will be all the way on the back left of your car. In all honestly, I had to take a photo of the back of the car to see what I was doing (see photo above) because I couldn’t see well. To find the filter, I looked at the tab of the new filter and found it on the old filter tab (physical examples are great, ya’ll).  The instructions are to lift and pull the filter out.  My partner gave me hand on this part and he used  vice-grip pliers to yank out the filter and did not say he needed to lift up on the filter.


Once the filter is removed try not to howl in disgust when you see it! The new filter slides back in fairly easily – remember that the open side is the top of the filter.

Put the glove box back in, and remember to twist the light back in.  Finally, apply a lot of pressure to the glove box when screwing the screws back in.  The pressure is needed to make sure the spaces align with the holes for the screw.


Hope you enjoy this quick car repair (it really took about 30 minutes to be done) that saves you about $60 and at least a few minutes for commuting.


*There are parts of the Nissan Versa that I have found particularly challenging to repair like the headlights or to have the oil changed.  Other things, like replacing the battery or the back windshield wiper can be done with ease.

Follow by Email
Continue Reading

Formatting: Leading Zeros

How many times have you exported data and realized a little too late that the leading zeros in constituent IDs were no longer showing up?

I know I have, and much to my chagrin I have had to re-send the file or spend time working through a process of making Excel or CSV format the leading zero appropriately.  I found a way using the Python package, pandas that makes leading zero formatting fairly easy and you don’t have to  add zeros or concat two cells together like you may consider doing in using Excel.

Below is an example data and the the steps that I followed to when I found that zeros where disappearing in my Excel document.

Here is my “data” with the IDs formatted as text so the leading zeros are visible.  When I saved this workbook, I saved it as an Excel file.excel_sample

I then imported pandas in my Jupyter Notebook, as I would normally when loading a dataframe for work and before preparing a file to be used in SPSS.  I wanted to see the first few lines of the file using the DataFrame.head() method and saw that the leading zeros had been dropped.


After seeing that the leading zeros were not showing I checked the Excel file to confirm that the IDs were saved as text.  Unfortunately, the ID column was saved as text, so there was nothing to alter there.

My next attempt at resolving the issue involved an reading an Excel file, and attempting to change the ID format to string.  Regrettably that lead to an error that ended with 'The 'dtype' option is not supported with the 'python' engine.




I then read documentation about the method of reading CSVs in pandas.  From there, I saw that my earlier code, the object defining the datatype (dtype), was meant to be used with with the function read_csv().  Excited, I saved my example data as a CSV, and reloaded the dataframe and applied the datatype object.  In the example below, you can see that once the dtype is applied, the leading zeros are visible in the dataset. read_csv

After getting past the initial hurdle of finding out how I can format specific documents I found this object pretty quick and efficient. How have you found the best way to work with leading zeros, especially if you can only export into Excel?

Follow by Email
Continue Reading

Fitbit Charge HR Teardown

Before I purchased a Fitbit Charge HR I scrutinized over the details of different athletic trackers and their capabilities.  I chose the Fitbit Charge HR because it: tells time, acts like a pedometer, has a heart rate monitor, can track stair climbs, track your sleep, have alarms set, syncs with Bluetooth,  and has various notifications come through like phone calls.  Honestly, it is pretty neat that a watch that do all of that and still be about 1 inch wide.

Earlier this year, my partner had a Charge HR’s wrist strap break and the company sent him a new one.  I am grateful he let me take the old one apart.

Here is the complete teardown of the Fitbit Charge HR:

Tools Needed:

  • Fitbit Charge HR
  • Torx Screwdriver: T2 (I have this set and it is awesome Floureon 38-piece Precision Screwdriver)
  • Spudger
  • Small bowl or container for screws
  • Self Healing mat or light workspace – I use this because my counter is dark and shiny so it is hard to see small parts.



When you remove your Fitbit and flip it over you see the sensor.  Looking at the corners of the sensor plate you will see 4 torx shaped screws.  Torx screws are six sided star screws and are common in cars, bikes and other electronics.  When created, torx were initially tamper proof because the shape was strange, kind of like the 5 star pentalobe screw that Apple started using in the 2010s.  To remove the torx screws use the size T2 and they will come out right away.  I recommend putting them in a small container (I used a ramekin) so you can find them later.


Now that the screws are out take the spudger and push the plastic backing out of the housing case. Using a spugder is easy and it helps ensure that you won’t damage your screwdrivers or accidentally stab your fingers or workspace.  Spudgers are also nylon so you won’t damage your Fitbit or its case if you want to put it back together.

Once I removed circuit board from the Fitbit I glanced back at the sensor, or the part that touches my wrist.  It is somewhat arguable that the fitbit already displays the the most interesting things, because I think the sensor is pretty neat.


The sensor is the rectangular part that looks clear.  It is an optical sensor, so basically the same thing that is inside a computer mouse.  The two dots above and below the sensor are infrared LEDs and they blink the green light. To work together, the LEDs send off light into you arm and sensor detects different light levels being reflected back by oxygenated and deoxygenated blood.  The detection in different light measurement is how the pulse is recored. You can purchase a pulse oximeter at a drugstore, and they are found in hospitals – they are the little sensors that are put on your finger to make you look like E.T.  Because pulse oximeters are used in medical devices to also determine oxygen saturation, it is possible that Fitbit is measuring O2 levels in blood and simply not reporting it back, or the calculation between oxygenated and deoxygenated blood is not made to tell.


Once you flip over the band, or where the circuit board was, you will see a yellow circuit (flex circuit) that connects the sensor back to the main circuit board.  To the right, there is a black chip.  It is kind of funny that the chip is not on the main circuit board but that is postulated that the chip is an amp to measure the pulse as there is so much other stuff going on inside the Fitbit.



Now, looking at the main circuit board, you will see two yellow flex circuits.  One of the flex circuits connects to the sensor, as mentioned before.  The other flex circuit connects to the display, and part you interact with when wearing the device.


Next is the battery, which is the biggest part of the electronic, unsurprisingly. Below the battery is the lithium ion battery charger, which regulates charge current. The white plastic circle is an altitude sensor (barometer), which assists in measuring how many flights of stairs you climb.

Flipping over the circuit board is the main side that has more “stuff” on it. This is the slide you see the display. The display is an OLED (organic LED), and uses very little battery, which is important as the device is busy collecting other data. Above it is a Bluetooth antenna—this is how you sync your device and beat the pants off your buddies in challenges! The display and antenna are soldered onto the circuit board on the upper right side, and also held by two additional torx screws. I accidentally tore the circuit board removing the display, so take caution when removing this part. It is possible that this is connected so snugly to provide more stability for the display.


Near the vibration motor is a chip that is the OLED power supply. Then there are two shiny chips, one is 8 bit and one is a 32-bit. Because there is so much going on in the Fitbit it is postulated that is the function for having 2 processors: the 8-bit may handle the Bluetooth stuff (coming from the big chip that says NRF) and display, and the big shiny 32-bit chip handles all the data that is being measured.


Another cool thing that has 2 of the same pieces are the accelerometers. It is possible that there are 2 accelerometers to more accurately estimate all the movement that is happening in your arm.  (Fun fact: accelerometers are in computer mice, too!)


Hope you enjoyed the teardown!  I know I learned a lot, and I was also interested to be able to see similar parts as I have seen in other devices.


Follow by Email
Continue Reading

The Little Toaster that Didn’t: A Teardown


I had been eyeing the toaster in my office kitchenette for weeks before taking the sophisticated appliance home.  I have a thing for toasters, my colleagues from my first job can attest to that.  After all, they had witnessed my rage of not being able to eat toasted bagels for weeks before purchasing me one. Anyways, I took the beaut from my current office home and tried to dismantle the device.  Here’s what I learned:

Toasters come with screws that mean “Stay out!”.   I was able to figure this out because the screw has a very atypical screw head. The Neji-Saurus was of no help and those screw pliers are awesome. Toasters also have other ways to say “Stay out!”, like bits of twisty metal holding plates in place.  The screws and construction of the toaster is probably difficult for a reason.  That reason is because the electrical filaments (nichrome wire), the little metal bits that turn red, carry large amounts of electrical currents through them to make infrared radiation that makes toast!  Sure, this little toaster was unplugged and hasn’t been plugged in since its factory days – but I remained frightened.

Here is what I was able to teardown and learn about.

Here are the stay out screws – I stayed out.


Here is a demo of what it looks like when you press down on the white handle.

Here is the circuit board and where I learned the most.



The pencil is touching a metal tab.  When the metal lever is depressed ( that is the part you push down on to make toast), the metal tab connects with the electromagnet, and that is what holds the toast down.  On the other side, you see a white plastic button.  When the lever is pushed down, the white button goes to the metal prongs sticking up.  Those metal prongs are called contacts and they apply power to the nichrome wires that make toast! That is also why there are a bunch of wires coming out the prongs and running to the filaments!

Back to the metal tab.  To the right of the pencil there is a black box with yellow stuff around it.  That black box is the electromagnet.  The top metal part is what the metal tab sticks to and holds the bread down. The yellow bit is the electromagnet.  The circular black thing behind the green circuit is the darkener/ timing capacitor. The timing capacitor is really how long you want your toast to be toasted / how long power is applied to the nichrome wires. Capacitors are basically like little batteries that store  electrical energy.  So once the timer is done, the electromagnet releases the metal tab, and up pops your toast!

Follow by Email
Continue Reading