Hi sorry so my code used to run perfectly but then I added this other piece of code but then i deleted it using Crtl and Z but it went onto the init.py file and Im not sure if i edited something or not but not my programme wont run anymore and im unsure on how to fix it...
#๐ I think i accidentally edited _init_.py.
28 messages ยท Page 1 of 1 (latest)
@red oxide
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
import csv
import pandas
import serial
import statistics
#update seial from the micro:bit
ser = serial.Serial() #shortening serial.Serial() to ser
ser.baudrate = 115200 # needed to get the correct signal from the micro:bit
#connecting the right srial port
#Type Device Manager in the start menu
# Try whichever COM appears (COM4 in this example) (based on what device manager shows)
ser.port = "COM6"
print("Type CTRL + C to safety exit.")
ser.open()
try:
while True:
lightlevel = str(ser.readline())
lightlevel = lightlevel[2:]
lightlevel = lightlevel.replace(" ","")
lightlevel = lightlevel.replace("'","")
lightlevel = lightlevel.replace("\\r\\n","")
lightlevel = lightlevel.replace("\\n","")
lightlevel = lightlevel.replace("\\r","")
lightlevel = int(lightlevel)
print(lightlevel)
path = "DATACOLLECTION.csv"
f = open(path, "a", newline='')
#change csver to csv1 or something
csver = csv.writer(f)
csver.writerow([lightlevel])
f.close()
except ValueError: #ignores blank inputs(prob not a worry here)
pass
except KeyboardInterrupt:
#print("\nSafely closing serial connection")
ser.close()
#print("Terminated")
print("\n")
# Create a pandas table so we can perform statistics on it
colnames = ['lightlevel']
data = pandas.read_csv('DATACOLLECTION.csv', skiprows=[0], names=colnames)
#the colnames should be seperate also figure out what to do here ^^
# Turn a given column into a list
measurement_CSV = data.lightlevel.tolist()
mean1 = statistics.mean(measurement_CSV)
median = statistics.median(measurement_CSV)
maximum = max(measurement_CSV)
# Get the mean (average) score
print("The average measurement was: ", round(mean1,2))
# Get the median (middle) score
print("The median measurement was: ", round(median,2))
# Get the maximum value
print("The maximum value was: ", round(maximum,2))
# Analysing Data
x = int(statistics.median(measurement_CSV))
#this can be changed based on when i delete my other values from previous goes
if x < 600:
print("You're light levels middle/median value is above 600.. \nYou might want to think about sleeping in a darker room.")
else:
print("You're light levels middle/median value is below 600.. \nThats great, a dark room for sleep is always good!")
print("\n")
physical_wellbeing = int(input("1-10 how you physically feel"))
emotional_wellbeing = int(input("1-10 how you emotionally feel"))
enviornmental_wellbeing = int(input("1-10 how you rate enviornment"))
average_mood = statistics.mean([physical_wellbeing, emotional_wellbeing, enviornmental_wellbeing])
average_mood2 = round(average_mood,2)
print("So overall youre feeling about a:", average_mood)
path = "DATACOLLECTION.csv"
f = open(path, "a", newline='')
#change csver to csv1 or something
csver = csv.writer(f)
csver.writerow([mean1, median, maximum, average_mood])
print("I have added the following data to your DATACOLLECTION.csv")
print([physical_wellbeing, emotional_wellbeing, enviornmental_wellbeing, average_mood])
print("")
f.close()
If anyone could please help im really unsure on what i edited
if you're not sure how would we be sure haha
i would recommend learning git or some sort of version control to avoid this in the future haha
the error youre getting is pointing to this line here
data = pandas.read_csv('DATACOLLECTION.csv', skiprows=[0], names=colnames)
so my first question would look at whats in the .csv file
ok ok i will now
on 357 that shouldnt be there
ah i just deleted it
its fine now
ahhh god ive just found out a bigger problem in it
lol
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.