Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Creating A List of DataFrames & Manipulating Columns in Each DataFrame
#1
Hello Everyone!
Would you help solving the following problem. I want to create a list made up of several dataframes, access each dataframe through a loop and once a dataframe has been reached, use another loop to access the column(s) of that dataframe and print elements of the column(s) or do something else with it.

The output i want to get through that process should look something like this:
208.185 140.87 237.11
208.76 140.14 232.9
209.59 140.91 237.47
207.575 139.8005 232.18

But this is what i currently get using the current script:

[0 207.805
1 208.760
Name: AAPL, dtype: float64, 0 140.81
1 140.14
Name: MSFT, dtype: float64, 0 238.14
1 232.90
Name: TSLA, dtype: float64]
[0 207.805
1 208.760
Name: AAPL, dtype: float64, 0 140.81
1 140.14
Name: MSFT, dtype: float64, 0 238.14
1 232.90
Name: TSLA, dtype: float64]
[0 207.805
1 208.760
Name: AAPL, dtype: float64, 0 140.81
1 140.14
Name: MSFT, dtype: float64, 0 238.14
1 232.90
Name: TSLA, dtype: float64]

Script:
#import all modules
from yahoofinancials import YahooFinancials
import pandas as pd
import numpy as np
#Stock stickers to get data - declared globally
stocks = ['AAPL','MSFT','TSLA']

#Function to extract data
def stockdata():
    yahoo_financials = YahooFinancials(stocks)
    price = yahoo_financials.get_current_price()
    Open = yahoo_financials.get_open_price()
    return(price, Open)
getval = stockdata()

dF = pd.DataFrame(getval)
df_list = (dF.AAPL, dF.MSFT, dF.TSLA)
list_df = list(df_list)
for u in list_df:
    print(list_df)
Thank you
Quote
#2
df_list in your code is a tuple of pd.Series instances. You can access Series elements, e.g. as follows: dF.AAPL.values.
Something like this:

for u in pd.np.hstack(df_list):
    print(u)
should print all items consequently.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  manipulating a dataframe - pandas nsx200 2 155 Nov-14-2019, 10:38 AM
Last Post: nsx200
  Pandas dataframe columns collapsed in Spyder when printing UniKlixX 2 132 Nov-04-2019, 07:00 AM
Last Post: UniKlixX
  How modify the DataFrame columns SriRajesh 2 188 Sep-12-2019, 03:14 PM
Last Post: SriRajesh
  Double 'for' loop and writing in a new columns dataframe marco_ita 0 206 Sep-07-2019, 12:44 PM
Last Post: marco_ita
  Compare between 2 DataFrames Nidhesh 2 239 Jul-26-2019, 08:16 AM
Last Post: Nidhesh
  Giving index when joining dataframes kw42chan 1 403 Jul-06-2019, 06:19 AM
Last Post: kw42chan
  Problem with creating DataFrame using Dictionary ift38375 8 442 Jul-02-2019, 05:39 PM
Last Post: ThomasL
  Could anyone help me get the jaccard distance between my dataframes please? :) a_real_phoenix 0 442 Jun-27-2019, 06:01 PM
Last Post: a_real_phoenix
  [pandas] How to re-arrange DataFrame columns SriMekala 8 991 Jun-22-2019, 12:55 AM
Last Post: scidam
  Two dataframes merged Ecniv 10 786 Jun-16-2019, 09:10 PM
Last Post: Ecniv

Forum Jump:


Users browsing this thread: 1 Guest(s)