TypeError: cannot convert the series to <class 'float'>

Hi there,

Having a bit of challenge ingesting data into influxdb v2. My data is in a data frame and I keep getting this error (TypeError: cannot convert the series to <class ‘float’>).
This is a view of my data

image

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 500 entries, 0 to 499
Data columns (total 6 columns):
 #   Column     Non-Null Count  Dtype  
---  ------     --------------  -----  
 0   timestamp  500 non-null    int64  
 1   open       500 non-null    float64
 2   high       500 non-null    float64
 3   low        500 non-null    float64
 4   close      500 non-null    float64
 5   volume     500 non-null    float64
dtypes: float64(5), int64(1)
memory usage: 23.6 KB

I created a Point object as follows

def parse_data(df):
    return Point("crypto_ohlcv") \
            .tag("exchange", "binance") \
            .field("open", df['open'].astype(float)) \
            .field("high", df['high'].astype(float)) \
            .field("low", df['low'].astype(float)) \
            .field("close", df['close'].astype(float)) \
            .field("volume", df['volume'].astype(float))\
            .time(df.timestamp)

and trying to injest the data as follows

write_api.write(bucket=bucket, org=org, record=parse_data(data))

Any suggestions on what could be the issue will be helpful

I would say that is a pandas misunderstanding. It doesn’t work that way.
You fill a single data point, but pass the whole pandas dataframe column e.g. df['open'] to convert it to float. That’s why you get this error message.

Hi @creative_sawa,

the client supports directly saving Pandas Dataframe.

For more info see:

Regards

1 Like

Thank you. Indeed it had to do with indexes. My best option was to use the the data frame insertion of the library as opposed to trying to loop through it