熊猫:将Yfinance字典转换为数据框,但该行为空

时间:2020-08-13 19:06:11

标签: python pandas dataframe yfinance

我有这样的Yfinance字典:

{'zip':'94404', 'sector':'Healthcare', 'fullTimeEmployees':11800, 'circulatingSupply':无, 'startDate':无, 'regularMarketDayLow':67.99, 'priceHint':2 'currency':'USD'}

我想将其转换为DataFrame,但是输出没有Row的信息:

Jupyter Notebook视图:

enter image description here

2 个答案:

答案 0 :(得分:0)

# Data returned back by yfinance
stock = yf.Ticker('AAPL')

# Store stock info as dictionary
stock_dict = stock.info

# Create DataFrame from non-compatible dictionary
stock_df = pd.DataFrame(list(stock_dict.items()))


    0   1
0   zip 95014
1   sector  Technology
2   fullTimeEmployees   137000
3   longBusinessSummary Apple Inc. designs, manufactures, and markets ...
4   city    Cupertino
5   phone   408-996-1010
6   country United States
7   companyOfficers []
8   website http://www.apple.com
9   maxAge  1
10  address1    One Apple Park Way

答案 1 :(得分:0)

Data = {'zip': '94404', 'sector': 'Healthcare', 'fullTimeEmployees': 11800, 'circulatingSupply': None, 'startDate': None, 'regularMarketDayLow': 67.99, 'priceHint': 2, 'currency': 'USD'}

字典变量周围的三括号:

df = pd.DataFrame([Data])
df

结果:

     zip    sector   fullTimeEmployees  circulatingSupply   startDate   regularMarketDayLow priceHint   currency
0   94404   Healthcare  11800               None              None          67.99              2         USD