Python dataframe n00b help

Posted on
  • so I am doing this course 'Python and Statistics for Financial Analysis' and I am stuck at the first hurdle

    I am using Jupyter notebook and need to import some stock data

    ms = pd.DataFrame.from_csv('.microsoft.csv')

    the syntax looks okay but when I try to view the head, so to speak

    print(ms.head())

    it's not doing anything

    same with shape

    print(ms.shape)

    so, I'm guessing I'm not getting the ms data from pandas imported to Jupyter? at this stage, I know so little I'm not even sure where to start

  • Should this be the following?

    ms = pd.from_csv('.microsoft.csv')
    print(ms.head())
    
  • thanks, tried that but it doesn't seem to work? I'll paste a link to an image of where I am below

    https://imgur.com/a/hRihGYK

    what do you think please?


    1 Attachment

    • python jupyter dataframe.png
  • You've not written the same code as when you imported the facebook.csv into a data frame.
    You should only change the name of the object you're creating and the name of the csv file. Otherwise the code should be the same.

  • Looks like it should be

    ms = pd.Dataframe.from_csv('../data/Microsoft.csv')

    You were missing the data directory from the path and the note says that it's in the same directory as the fb can file...

  • thanks very mucc everyone, I have tried both versions

    BCarley and Cupcakes/danb- even just cut & pasted the suggestions but it is not loading
    what else cna I be misisng please?

    to run it, I juts hit enter but nothing

  • typo in mine by the looks of things - should be ../data/microsoft.csv not Microsoft.csv

  • ms = pd.read_csv('../data/microsoft.csv')
    

    Case is important.

    Edit: took me a long time to type on a phone keyboard.

  • ms = pd.read_csv('../data/microsoft.csv')

    thanks root, I am doing something wrong here... it is not working

  • where is the csv file relative to the notebook you're running?
    same directory? sub directory? in a different one (a different child of the parent dir?)

  • I broke it too. I think I've fixed it. Nope sorry the function is called read_csv

    https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html

  • Make sure you re-run the cell above so that pandas is imported.

  • if you are using from_csv you need to use it as pd.DataFrame.from_csv (...) which i missed the upper case F from in my previous example....

    if you are using read_csv you do it as pd.read_csv(...)

  • thanks very, very much- I will sit down with this later & try figure out where I have gone wrong

  • I'm not quite sure but soemthing is not loading or pulling form somewhere, when I try to get the fb data, it won't do anything either?

  • You'll need to post your code and error messages to let people know what is going wrong.

    I tried to reproduce what you describe (you have implied that you can execute the code without errors but that nothing has happened). However I cannot replicate this. If I fail to import pandas then I get a NameError. If I fail to define the path to the .csv correctly I get a FileNotFound error.

  • Christ. I hope the pay is good for this type of work..😎

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Python dataframe n00b help

Posted by Avatar for Jay242 @Jay242

Actions