Search code examples
pythonchartsplotlytypeerror

TypeError: 'module' object is not callable in plotly


from time import time
import plotly.graph_objects as go
import pandas as pd
def PrintChartData():
  data = pd.read_csv("eurusd_m1_03.03.2022.csv")
  return data

def PrintDataChart():
    data = pd.read_csv("eurusd_m1_03.03.2022.csv")
    chart_data= go.candlestick(x=data['time'],open=data['open'],high=data['high'],low=data['low'],close=data['close'])
  fig = go.figure(data=[chart_data])
  print(fig.show())

RESULT :

TypeError                                 Traceback (most recent call last)
<ipython-input-14-892406758100> in <module>
----> 1 PrintDataChart()

<ipython-input-12-2e832d51e638> in PrintDataChart()
      1 def PrintDataChart():
      2   data = pd.read_csv("eurusd_m1_03.03.2022.csv")
----> 3   chart_data = go.candlestick(x=data['time'],open=data['open'],high=data['high'],low=data['low'],close=data['close'])
      4   fig = go.figure(data=[chart_data])
      5   print(fig.show())

TypeError: 'module' object is not callable

Can anyone help me solve this problem? I want to call a .csv file to a dart But I encountered this error message.


Solution

    • dynamically creating hard coded file referenced in you code to make it runnable on any environment
    • two typos in your code
      1. candlestick() should be Candlestick()
      2. figure() should be Figure()
    import requests
    import pandas as pd
    import io
    from pathlib import Path
    
    
    # setup some data so code works
    f = Path.cwd().joinpath("eurusd_m1_03.03.2022.csv")
    pd.read_csv(
        io.StringIO(
            requests.get(
                "https://www.marketwatch.com/investing/currency/eurusd/downloaddatapartial?startdate=08/03/2022%2000:00:00&enddate=09/02/2022%2023:59:59&daterange=d30&frequency=p1d&csvdownload=true&downloadpartial=false&newdates=false"
            ).text
        )
    ).pipe(
        lambda d: d.rename(columns={c: c.lower() for c in d.columns}).rename(
            columns={"date": "time"}
        )
    ).to_csv(
        f
    )
    
    
    from time import time
    import plotly.graph_objects as go
    import pandas as pd
    
    def PrintChartData():
        data = pd.read_csv("eurusd_m1_03.03.2022.csv")
        return data
    
    
    def PrintDataChart():
        data = pd.read_csv("eurusd_m1_03.03.2022.csv")
        chart_data = go.Candlestick(
            x=data["time"],
            open=data["open"],
            high=data["high"],
            low=data["low"],
            close=data["close"],
        )
        fig = go.Figure(data=[chart_data])
        print(fig.show())
    
    
    PrintDataChart()