Search code examples
pythonpandasdataframefinance

Save column as a separate list? Python


just started learning how to use Pandas so please excuse the simplicity of the questions!

import pandas as pd

top100 = pd.read_html('https://robinhood.com/collections/100-most-popular')

Output:

[                     Name Symbol    Price  Today Market Cap  Popularity Analyst Ratings
0              Ford Motor      F    $6.81  0.73%     27.04B      942282         21% Buy
1                      GE     GE    $7.08  0.43%     61.84B      840895         62% Buy
2       American Airlines    AAL   $11.96  3.94%      6.05B      655044         20% Buy
3                  Disney    DIS  $118.70  0.61%    214.31B      619926         50% Buy
4         Delta Air Lines    DAL   $27.17  0.33%     17.25B      582985         63% Buy
..                    ...    ...      ...    ...        ...         ...             ...
95   Occidental Petroleum    OXY   $16.38  3.70%     14.65B       76389         12% Buy
96  Sorrento Therapeutics   SRNE    $7.15  7.04%      1.41B       76260             â
97                  Everi   EVRI    $5.84  3.95%    491.45M       74132        100% Buy
98                 Macy's      M    $6.69  2.90%      2.06B       73563          0% Buy
99    Viking Therapeutics   VKTX    $7.06  0.56%    515.44M       72412        100% Buy

[100 rows x 7 columns]]

My question is how can I save the Symbol column as a list somewhere? So like:

symbols_list = [F,GE, AAL ....]

Also can I save the corresponding Price of the symbols as well?


Solution

  • There is some mismatch regarding top100, as it's a list. So, just to add a point here, top100 should be pandas dataframe (top100 = top100[0])

    list_ = top100['Symbol'].tolist()
    

    To save the corresponding price (if you use 2d list):

    list_ = top100[['Symbol', 'Price']].tolist()
    

    To save the corresponding price (if you use dictionary):

    # mydict has keys as the elements in column Symbol, value as the elements in Price
    mydict = dict(zip(top100.Symbol, top100.Price))