I am reading a csv and saving(trying) certain columns into the my database. I did that and wanted to double check a row in my database, to see if everything was ok. However one of my columns was saved as b'd\x00\x00\x00\x00\x00\x00\x00'
. I was unsure what that meant and googled and found that it's binary(is that finding correct?) This really confused me. The value in that specific column and row in the csv file is 100
and in my model that specific column was indicated as an Integer. edit I'm using Flask with sqlalchemy.
Here's the relavant code:
my model
class DesiredClass(db.model):
id = db.Column(db.Integer, primary_key=True)
created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
speed = db.Column(db.Float, nullable=False) # in m/s
direction = db.Column(db.Float, nullable=False) # in degrees
different_value = db.Column(db.Integer, nullable=False) # in percent
example row in csv with their respective columns
speed; direction; different_value
32.2; 52.4; 100
reading csv and saving to db
df = pd.read_csv(filename, sep=';')
for i in df.index:
m = DesiredClass(
speed=df.loc[i, 'SPEED'],
direction=df.loc[i, 'DIRECTION'],
different_value=df.loc[i, 'DIFFERENT_VALUE'],
)
db.session.add(m) # add to db
db.session.commit() # perform them all
I then checked on my notebook to see what had been saved. And saw b'd\x00\x00\x00\x00\x00\x00\x00'
in the column for different_value
. All the other one's were saved in the correct format.
Therefore, 1) I'm confused why it shows that way, and that didn't happen to the other columns. 2) Where to even start? I doubled checked the csv and looked at that specific row that I was looking at to see if there was something weird. However it just has the value 100.
Thanks in advance.
Update
I'm using flask_sqlalchemy and sqlite. To check I used the jupyter notebook, ran what I had and then did the following there
result = DesiredClass.query.with_entities(DesiredClass.id, DesiredClass.speed, DesiredClass.direction, DesiredClass.different_value)
.
I then did result.first()