Python : Problem with " TypeError: float() argument must be a string or a number "

Hello !

I'm creating a CGI which allow to display graph from some data.

The datas looks like :



2020-01-13-00-00,384.00,350.00
2020-01-13-06-00,384.00,350.00
2020-01-13-12-00,384.00,350.00
2020-01-13-18-00,384.00,350.00
2020-01-14-00-00,384.00,350.00
2020-01-14-06-00,384.00,350.00
2020-01-14-12-00,384.00,350.00

I use the ipywidgets, pandas and plotly.express librarys in order to create a web page which will display a graph with two buttons : the first to display the graph and the second to display the graph with the trendline.

My script is :

import ipywidgets as widgets
import pandas as pd
import plotly.express as px
import os


 
####### Button 1 ########


 
button = widgets.Button(description="graph")
display(button)


 
def graph():
        df = pd.read_csv('/xxx/xxx/xxx/Test.txt')
        df.head()
        fig = px.line(df, x = 'Date', y ='Total Used', title='DF command graph')
        fig.update_traces(mode='markers')
        fig.show();
 


output = widgets.Output()
 


@output.capture()
def on_button_clicked(b):
        graph();


 
button.on_click(on_button_clicked)
display(output)




####### Button 2 #########
 


button2 = widgets.Button(description='trend')
display(button2)
 


def trend():
        df = pd.read_csv('/xxx/xxx/xxx/Test.txt')
        df.head()
        fig = px.scatter(float(df), x="Date", y="Total Used", trendline="ols")
        fig.show()
 


output2 = widgets.Output()
 


@output2.capture()
def on_button2_clicked(b):
        trend()
 


button2.on_click(on_button2_clicked)
display(output2)
 


graph()

The first step ( displaying the grap ) works prefectly :

But when I press the trend button, I've this error :

--------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/ipywidgets/widgets/widget_output.py in inner(*args, **kwargs)
    101                     self.clear_output(*clear_args, **clear_kwargs)
    102                 with self:
--> 103                     return func(*args, **kwargs)
    104             return inner
    105         return capture_decorator


<ipython-input-17-8774359d7459> in on_button2_clicked(b)
     41 @output2.capture()
     42 def on_button2_clicked(b):
---> 43     trend()
     44 
     45 button2.on_click(on_button2_clicked)


<ipython-input-17-8774359d7459> in trend()
     34     df = pd.read_csv('/home/timothee/Desktop/Test.txt')
     35     df.head()
---> 36     fig = px.scatter(float(df), x="Date", y="Total Used", trendline="ols")
     37     fig.show()
     38 


TypeError: float() argument must be a string or a number, not 'DataFrame'

I know that in this situation, the trendline make no sense, bujt it's just an example.

Could you show me how to fix this error ?

According to : Pandas' api reference

pandas.read_csv returns

DataFrame or TextParser
A comma-separated values (csv) file is returned as two-dimensional data structure with labeled axes.

Which is not the string or number, that float() expects