Python pandas influxdb 2.0

I have previously been using influxdb version 1
Tested the version 2.0 beta and am having zero luck batch writing a pandas dataframe at speed

This is what I am following. Converting to line protocol seems to be a very expensive step that is taking a very long time:

def lp(df,measurement,tag_key,field,value,datetime):
lines= [str(df[measurement][d]) + “,”
+ str(tag_key) + “=” + str(df[tag_key][d])
+ " " + str(df[field][d]) + “=” + str(df[value][d])
+ " " + str(int(time.mktime(df[datetime][d].timetuple()))) + “000000000” for d in range(len(df))]
return lines

This doesn’t feel right to be honest - I have big dataframes I need to write to influxdb. Can someone show me some example code for how to do this?

Hello @Ben_Burden,
Yes that’s very expensive. I wouldn’t use it (I just included that script while the method was in development to help new users get started with InfluxDB).

Please take a look at this feature request.

And thank you for the reminder. I will update that blog now.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.