Skip to content
Advertisement

How to extract elements from a filename and move them to different columns?

I have a filenames which I converted into a list. The list has the following elements:

JavaScript

My goal is to extract elements from this list and fill out a dataframe, which should look like this:

enter image description here

LINK TO THE GOOGLE SHEETS CONTAINING THE IMAGE ABOVE: https://docs.google.com/spreadsheets/d/1kuX3M4RFCNWtNoE7Hm1ejxWMwF-Cs4p8SsjA3JzdidA/edit?usp=sharing

WHAT I’VE DONE SO FAR is the following code:

JavaScript

But, this one does not leave empty spaces thus not doing what I needed.

Thank you very much in advanced.

Advertisement

Answer

As per number of the comments. It’s a pain because the tokens in the filename are not fully fixed format. Quite a lot of conditional logic

  1. have defined two additional lists mi instruments and oxygen whatever it is.
  2. first pass is in building dict that is pandas standard format
  3. then work through conditional logic after have base data frame
JavaScript

output

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement