Importing data into Mathematica



hi I'm Ben's wiggle and welcome to this mathematic screencast on importing data into Mathematica by importing data into Mathematica lets us take data from an oscilloscope lab view or from some other source and put it into Mathematica for analysis and plotting Mathematica has a wide range of available import formats we can see the full list of available import formats by using the environment variable dollar sign import formats and an environment variable in Mathematica always starts with a dollar sign and we can see the list by hitting shift enter and there it is we see a list of image formats audio formats binary data video and most importantly text-based data formats which you'll commonly use in this course and the most common example you'll probably see is the CSV or comma separated variables file so before we import a comma separated variables file I want to first look at one in a text editor so the CSV file is a text-based data format so a program like notepad can open it and just show you the strings of ASCII characters that it's made from so in this case a CSV file is a series of columns each separated by a comma and rows each on a new line so this particular data set came from an oscilloscope and so it has a time column channel 1 voltage column and a channel 2 voltage column and for some reason a blank column was saved at the end and so we can go back to Mathematica and import that using import that data using the function import so the import function has a minimum of one argument which is the file path so this brings up a dialog box by going to insert file path and you can select the file you'd like to import and it inserts the full path of the file and we can give this a name and Mathematica says a very large output was generated here's a sample of it you'll notice that it doesn't look exactly the same as the file in Notepad because it has these curly brackets which is how Mathematica denotes lists and so we can make the just the viewing format in Mathematica look similar by selecting a subset of it so we say data CSV we'll look at the 1st through the 6th rows and we'll look at all columns of this data set and let's use the function table form to view it and then we have a nicely formatted data table so you might be wondering how Mathematica knew this was a comma separated variables file and that's because of the dot csv extension it assumes that the extension accurately conveys the file type but in the case where you don't have an extension or the file type is not 1 the extension is not one that Mathematica recognizes you can still use the import function and you still need to insert a file path so insert file path and now I'm going to pick a data set with no extension on the file name and all I need to do in this case is I happen to know that that is a comma separated variables file anyway so I give it the option and explicitly tell it this is a comma separated variables file and if we import that we see the same very large output was generated and here is a sample of it and that is how you import data into Mathematica and remember if you ever get stuck the help is a valuable source of both examples and options that are available for any of these functions like import thanks for watching

7 thoughts on “Importing data into Mathematica

  1. Thank you very much!
    Just an observation: with your soft and calm voice it seems as if HAL 9000 is telling me how to use Mathematica, it's pretty fun! 

  2. thank u and please explicitly mention "Importing CSV file into Mathematica" so people will reach this great video quickly

Leave a Reply

Your email address will not be published. Required fields are marked *