简体   繁体   中英

How do you create a data-frame from NoneType?

I'm currently using the ffn library to analyze stock data. However, while using one of the functions to get information I've gotten back an object I can't manipulate.

While trying to turn the object back into a pandas data frame i get the error: Invalid file path or buffer object type: <class 'NoneType'>

Is there anyway to read this data type back into pandas?

From the python docs: https://docs.python.org/3/library/constants.html

None The sole value of the type NoneType . None is frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to None are illegal and raise a SyntaxError.

If you put nothing (the absence of value) inside of DataFrame the DataFrame would be empty. NoneType means that the object is equal to the singleton None.

So to create a DataFrame from NoneType you could test for None and if the result is True create an empty DataFrame.

import pandas as pd
if result is None:
    df = pd.DataFrame()

But probably thats not what you want. More likely the problem is in your acquisition of the object in the first place. There is no information in that NoneType object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM