I am trying to visualize the EEG data fie which is in .edf file format.For this purpose I am using MNE python.
here is my code
import mne
file = "/home/test.edf"
data = mne.io.read_raw_edf(file,preload=True)
Whenever I run this code below error massage is showing
ValueError: not enough values to unpack (expected 3, got 0)
I could not figure out where is my wrong.
It's not possible to use use the file by specifying the path, event if you add a "~", the directory won't be identified. Better you try to be in the exact directory and try reading the file, i.e go to your home directory and then try specifying the file.
import mne
file = "test.edf"
data = mne.io.read_raw_edf(file)
Related
I am exporting a panda data frame as an excel file on FTP and using the below code. The code is creating a file on FTP. The issue here is that if I am make any change in the code and expecting a different output file it is creating the same output file as before. However if I change the file name in: myFTP.storbinary('STOR %s.xlsx' %filename,bio)..It works fine. Moreover, if I made the output on my local keeping the same name it also works fine. I dont want to change the file name every time I make some change in my code."It is not creating a different file with the same name" Below is the code:
myFTP = ftplib.FTP("ftp address","username","password)
myFTP.cwd("change directory/")
buffer=io.BytesIO()
df.to_excel(buffer,index=False)
text = buffer.getvalue()
bio = io.BytesIO(text)
file name = 'FileName_{0}{1}'.format(current_year,current_month)
myFTP.storbinary('STOR %s.xlsx'%file_name,bio)
myFTP.close()
Name of the output file must be: FileName_currentyearcurrentmonth
file name = 'FileName_{0}{1}'.format(current_year,current_month)
If this line of code is as it is in your code, well. It seens you have a syntax error. Also in cases like this contextual manager are actually pretty usefull. Why dont you try doing like this. So if you get an error well you dont keep your file open
with ftplib.FTP("ftp address","username","password) as myFTP:
myFTP.cwd("change directory/")
buffer=io.BytesIO()
df.to_excel(buffer,index=False)
text = buffer.getvalue()
bio = io.BytesIO(text)
file name = 'FileName_{0}{1}'.format(current_year,current_month)
myFTP.storbinary('STOR %s.xlsx'%file_name,bio)
I am using pyomo on Jupyter Notebook. I have kept keepfiles = true in solve.I am able to get the location of .sol file where it is stored. How can I get the filename of the .sol file created for the current instance?
I have used following:
from pyomo.opt import SolverFactory
SolverFactory("cbc").options['solu']="solution_file.sol"
But this does not work in creating the desired solution file.
If you add the keepfiles=True option to your call to solve the temporary files that are used to pass the model to the solver and read in the results will not be deleted and the path to them will be printed on the screen. So I would create and call your solver using something like:
from pyomo.opt import SolverFactory
solver = SolverFactory("cbc")
solver.solve(model, keepfiles=True)
I cannot load a csv file using the numpy loadtxt function. There must be something wrong with the file format or something else. I am using anocanda notebook on macbook.
OSError: Macintosh HD\\Users\\binhao\\Downloads\\Iris_data.csv not found.
np.loadtxt("Macintosh HD\\Users\\binhao\\Downloads\\Iris_data.csv")
I tried a solution I found on stackflow involved using:
f = open(u"Macintosh HD\\Users\\binhao\\Downloads\\Iris_data.csv")
f = open("Macintosh HD\\Users\\binhao\\Downloads\\Iris_data.csv")
Above don't work - No such file or directory error
Most of the time is due to some non-escaped charter, try to use raw string:
r"Macintosh HD\\Users\\binhao\\Downloads\\Iris_data.csv"
I am currently working on an automation project for a company, and one of the tasks require that I loop through a directory and convert all the pdf files into a CSV file. I am using the camelot-py library (which has been better than the others I have tried). When I apply the code below to a single file, it works just fine; however, I wish to make it loop through all pdf files in the directory. I get the following error with the code below:
"OSError: [Errno 22] Invalid argument"
import camelot
import csv
import pandas as pd
import os
directoryPath = r'Z:\testDirectory'
os.chdir(directoryPath)
print(os.listdir())
folderList = os.listdir(directoryPath)
for folders, sub_folders, file in os.walk(directoryPath):
for name in file:
if name.endswith(".pdf"):
filename = os.path.join(folders,name)
print(filename)
print(name)
tables = camelot.read_pdf(filename, flavor = 'stream', columns= ['72,73,150,327,442,520,566,606,683'])
tables = tables[0].df
print(tables[0].parsing_report)
tables.to_csv('foo2.csv')
I expect all files to be converted to '.csv' files but I get the error 'OSError: [Errno 22] Invalid argument'. My error appears to be from line 16.
I don’t know if you have the same problem, but in my case I made a really stupid mistake of not putting the files in the correct directory. I was getting the same error but once I found out the problem, script works within a regular for loop.
Instead of the to methods, I am using the bulk export to export the results in sql, but that should not be a problem.
I am currently using asksaveasfile to save the file, and it is working fine. The only issue I am having is that I cant get the new file name. I know asksaveasfilename exists but if I use them both together they will pop up two windows which I dont want to happen. If I try printing the output of asksaveasfile i get the following:
<_io.TextIOWrapper name='/home/work/newfile.txt' mode='w' encoding='UTF-8'>.
Is there a way I can just get the file name out of this?
Just use the .name attribute of the result of asksaveasfile:
import tkinter
file = tkinter.filedialog.asksaveasfile()
name = file.name
Or you can use asksaveasfilename then open the file yourself:
name = tkinter.filedialog.asksaveasfilename()
file = open(name,'w')
This way you could also use a with statement to ensure the file is closed properly which would be a good idea anyway:
name = tkinter.filedialog.asksaveasfilename()
with open(name,'w') as f:
NotImplemented #do stuff with the file