AttributeError: 'SerialBus' object has no attribute 'can' - python-3.x

I am writing a python code to receive the can data via a USB2CAN device. I receive the following error:
AttributeError: 'SerialBus' object has no attribute 'can'
from can.interfaces import serial
import random
import time
import datetime
import matplotlib.pyplot as plt
ser= can.interfaces.serial.serial_can.SerialBus('COM5',115200,timeout=None,rtscts=0)
for i in range(100) :
s= ser.can.interfaces.serial.SerialBus._recv_internal(timeout=None)
print(s)

Related

Backtrader in Python AttributeError: 'DataFrame' object has no attribute 'setenvironment'. What's the problem and how to solve it?

new to backtrader
when getting starting with the documentation and implemnting the code, i get the error
AttributeError: 'DataFrame' object has no attribute 'setenvironment' in the cerebro.adddata line
you can check in the image below:
the error when i run cerebro.adddata
i have already tried the solution mentionned in this Backtrader error: 'DataFrame' object has no attribute 'setenvironment' but nothing changed
if anyone has experienced this before and could help will be nice, this is the code i'm using and i don't know where the problem is:
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import datetime # For datetime objects
import os.path # To manage paths
import sys # To find out the script name (in argv[0])
import pandas as pd
import pandas_datareader as pdr
#import backtrader platform
import backtrader as bt
if __name__ == '__main__':
# Create a cerebro entity
cerebro = bt.Cerebro()
#create a data feed
data= pd.read_csv('EURUSD20102020')
#add the Data Feed to Cerebro
cerebro.adddata(data)
# Set our desired cash start
cerebro.broker.setcash(100000.0)
# Print out the starting conditions
print('Starting Portfolio value: %.2f' % cerebro.broker.get_value())
# Run over everything
cerebro.run()
# Print out the final result
print('Final Portfolio Value: %.2f' % cerebro.broker.get_value())

AttributeError: module 'matplotlib' has no attribute 'scatter'

I'm trying to make cluster of latitude and longitude.
the code gave an error in plt.scatter(data['Lng'],data['Lat']) line
the error is:
AttributeError: module 'matplotlib' has no attribute 'scatter'
code:
import numpy as np
import pandas as pd
import matplotlib as plt
import seaborn as sns
sns.set()
from sklearn.cluster import KMeans
data = pd.read_csv("pk.csv")
data.head()
lat_long = data.drop(['country', 'iso2','admin', 'capital','population',
'population_proper'] , axis = 1)
lat_long.head()
plt.scatter(data['Lng'],data['Lat']) # error here
It should be:
import matplotlib.pyplot as plt
Or it can be:
from matplotlib import pyplot as plt
Also you can read PEP 328 for more information and clearity.

'float' object has no attribute 'exp' in spyder python

import numpy as np
from scipy import interpolate
import pylab as py
import pandas as pd
def func(x1):
return x*np.exp(-5.0*x1**2)
dataset=pd.read_excel('Messwerte_FIBRE1.xlsx')
dataset=dataset.drop([0])
index=[1]
index2=[9]
x=dataset.iloc[:, index]
y=dataset.iloc[:, index2]
x1=np.array(x)
y1=np.array(y)
fvals=func(x1)
File "C:/Users/Windows 10/.spyder-py3/RBF.py", line 10, in func
return x*np.exp(-5.0*x1**2)
AttributeError: 'float' object has no attribute 'exp'
Any1 can help me to solve this problem?
Here is the png of my textfile
np.exp(...)
'float' object has no attribute 'exp'
This means that you likely have redefined the name np, and now it's a floating-point number and not the numpy module any more.
Look around your code for np = ....

Using NASDAQ API, can't use decode on urlopen

I'm trying to use the NASDAQ API from https://github.com/Nasdaq/DataOnDemand but cannot seem to get it to work in Python 3.
I fixed the urllib stuff and first got an error at line 92 which I fixed by encoding it to utf-8
Before:
request_parameters = urllib.parse.urlencode(values)
Fix:
request_parameters = urllib.parse.urlencode(values).encode('utf-8')
But now i get an error on:
response = urllib.request.urlopen(req)
>>>TypeError: cannot use a string pattern on a bytes-like object
When i try to fix it by decoding i get:
response = urllib.request.urlopen(req).decode()
OR
response = urllib.request.urlopen(req).decode('utf-8')
>>>AttributeError: 'HTTPResponse' object has no attribute 'decode'
This is what my imports look like:
import urllib.request
import urllib.parse
import xml.etree.cElementTree as ElementTree
import re
from pprint import pprint
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import datetime as dt
Any help is appreciated

How to use waldboost detector in opencv-3.2 using python

import cv2
import numpy as np
detector=cv2.createWaldBoost()
but this code is showing me error
detector=cv2.createWaldBoost()
AttributeError: module 'cv2' has no attribute 'createWaldBoost'

Resources