Im trying to convert midi files to csv, make changes, and then change back into midi. I wan to do this all in python using the py_midicsv module.
However, I run into an error when i try to follow the documentation on: https://github.com/timwedde/py_midicsv
#Convert back to csv
import py_midicsv
csv_string = py_midicsv.midi_to_csv("example.mid")
midi_object = py_midicsv.csv_to_midi(csv_string)
The code above is straight from the documentations but I run into the error:
ValueError Traceback (most recent call last)
<ipython-input-17-2cb6d586ec9e> in <module>
1 #Convert back to csv
2 import py_midicsv
----> 3 midi_object = py_midicsv.csv_to_midi(csv_string)
~/.local/lib/python3.6/site-packages/py_midicsv/csvmidi.py in parse(file)
44 pattern.append(track)
45 else:
---> 46 event = csv_to_midi_map[identifier](tr, time, identifier, line[3:])
47 track.append(event)
48 pattern.make_ticks_rel()
~/.local/lib/python3.6/site-packages/py_midicsv/csv_converters.py in to_AfterTouchEvent(track, time, identifier, line)
24
25 def to_AfterTouchEvent(track, time, identifier, line):
---> 26 cannel, value = map(int, line)
27 return AfterTouchEvent(tick=time, channel=channel, value=value)
28
ValueError: too many values to unpack (expected 2)
What does this error mean and how can I fix things?
cannel, value = map(int, line)
the problem is with this line.
you are trying to unpack this map object into 2 objects, but it consists of more than 2 object, so python don't know what to do with the rest of the values.
you will need to understand what this map object contains, and what data you need to get from it. try to print it and see what data it holds.
Related
I am trying to create a multiple alignment fasta file from an user search of a gen and a sequence. To create this fasta file I am using the following:
for seq in fasta_result:
ofile.write(">" + names[x] + "\n" + fasta_result[y] + "\n")
x +=1
y +=1
This is working fine as long as the name list is a simple list:
names = ['name_1','name_2','name_3','name_4']
It gives me a fasta file with the intended result. However, my intention is that instead of generic names like 'name_1', 'name_2', etc... I want to get the names of the genomes.
I have a function that does the job:
example = 'Rv0001'
genome = 'tuberculosis'
print(alignment_search(example, genome)
The result is a list:
['Rv0001', 'MSMEG_RS33460', 'MRA_RS00005', 'BQ2027_RS00005']
However, when I modify the first part of the code to have:
names = alignment_search(example, genome)
I get the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/var/folders/pq/ghtv3wj159j681vy0ny3tz9w0000gp/T/ipykernel_34390/940860269.py in <module>
18 genome = genome_location(before, after, alignment)
19
---> 20 filename = custom_fasta(genome, example, genome)
21
22 aln = AlignIO.read('/Users/dissertation/Documents/Dissertation-real/cgi-mycoapollo/db/genomes/' + filename + '_out.fasta','fasta')
/var/folders/pq/ghtv3wj159j681vy0ny3tz9w0000gp/T/ipykernel_34390/573793128.py in custom_fasta(locations_dict, example, genome)
55
56 for seq in fasta_result:
---> 57 for value in names:
58 ofile.write(">" + names[x] + "\n" + fasta_result[y] + "\n")
59
TypeError: 'NoneType' object is not iterable
I am not sure why it gives me this error, I have checked that the result of the function alignment_search(example, genome) is indeed a list type:
print(type(alignment_search(example, genome)))
<class 'list'>
So why is it working with a simple list but when it depends on the result of a function it gives the NoneType error?
Thanks!
I am trying to run the following code over a CSV file, but the code is showing an error that the input data type should be a str and not an int, but I have checked the data type and it is a float. I have tried every conversion from string, to float, to int, but nothing seems to work. please tell me what am I doing wrong.
print(stdized_data.X.dtypes)
for element in stdized_data:
if element != 0:
log(element + 1)
else:
log(element + 2)
###################################OUTPUT################################
float64
--------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-163-6e534ce31c6a> in <module>()
9 for element in stdized_data:
10 if element != 0:
---> 11 log(str(element) + 1)
12
13 else:
TypeError: must be str, not int
I have loaded the file using pd.read_csv function.
What you need to do is probably this -
log(str(element + 1))
What you are doing is -
log(str(element) + 1)
You have converted element to string but 1 is still an integer and you can't add string and integer
I have this code that will allow me to count the number of missing rows of numbers within the csv for a script in Python 3.6. However, these are the following errors in the program:
Error:
Traceback (most recent call last):
File "C:\Users\GapReport.py", line 14, in <module>
EndDoc_Padded, EndDoc_Padded = (int(s.strip()[2:]) for s in line)
File "C:\Users\GapReport.py", line 14, in <genexpr>
EndDoc_Padded, EndDoc_Padded = (int(s.strip()[2:]) for s in line)
ValueError: invalid literal for int() with base 10: 'AC-SEC 000000001'
Code:
import csv
def out(*args):
print('{},{}'.format(*(str(i).rjust(4, "0") for i in args)))
prev = 0
data = csv.reader(open('Padded Numbers_export.csv'))
print(*next(data), sep=', ') # header
for line in data:
EndDoc_Padded, EndDoc_Padded = (int(s.strip()[2:]) for s in line)
if start != prev+1:
out(prev+1, start-1)
prev = end
out(start, end)
I'm stumped on how to fix these issues.Also, I think the csv many lines in it, so if there's a section that limits it to a few numbers, please feel free to update me on so.
CSV Snippet (Sorry if I wasn't clear before!):
The values you have in your CSV file are not numeric.
For example, FMAC-SEC 000000001 is not a number. So when you run int(s.strip()[2:]), it is not able to convert it to an int.
Some more comments on the code:
What is the utility of doing EndDoc_Padded, EndDoc_Padded = (...)? Currently you are assigning values to two variables with the same name. Either name one of them something else, or just have one variable there.
Are you trying to get the two different values from each column? In that case, you need to split line into two first. Are the contents of your file comma separated? If yes, then do for s in line.split(','), otherwise use the appropriate separator value in split().
You are running this inside a loop, so each time the values of the two variables would get updated to the values from the last line. If you're trying to obtain 2 lists of all the values, then this won't work.
I have written a code in python to generate a sequence of ARIMA model's and determine their AIC values to compare them.The code is as below,
p=0
q=0
d=0
for p in range(5):
for d in range(1):
for q in range(4):
arima_mod=sm.tsa.ARIMA(df,(p,d,q)).fit()
print(arima_mod.params)
print arima_mod.aic()
I am getting a error message as below,
TypeError Traceback (most recent call last)
<ipython-input-60-b662b0c42796> in <module>()
8 arima_mod=sm.tsa.ARIMA(df,(p,d,q)).fit()
9 print(arima_mod.params)
---> 10 print arima_mod.aic()
global arima_mod.aic = 1262.2449736558815
11
**TypeError: 'numpy.float64' object is not callable**
Remove the brackets after print arima_mod.aic(). As I read it, arima_mod.aic is 1262.2449736558815, and thus a float. The brackets make python think it is a function, and tries to call it. You do not want that (because it breaks), you just want that value. So remove the brackets, and you'll be fine.
import sys
def func():
T = int(next(sys.stdin))
for i in range(0,T):
N = int(next(sys.stdin))
print (N)
func()
Here I am taking input T for for loop and iterating over T it gives Runtime error time: 0.1 memory: 10088 signal:-1 again-again . I have tried using sys.stdin.readline() it also giving same error .
I looked at your code at http://ideone.com/8U5zTQ . at the code itself looks fine, but your input can't be processed.
Because it is:
5 24 2
which will be the string:
"5 24 2"
this is not nearly an int, even if you try to cast it. So you could transform it to the a list with:
inputlist = next(sys.stdin[:-2]).split(" ")
to get the integers in a list that you are putting in one line. The loop over that.
After that the code would still be in loop because it want 2 integers more but at least you get some output.
Since I am not totally shure what you try to achieve, you could now iterate over that list and print your inputs:
inputlist = next(sys.stdin[:-2]).split(" ")
for i in inputlist
print(i)
Another solution would be, you just put one number per line in, that would work also
so instead of
5 24 2
you put in
5
24
2
Further Advice
on Ideone you also have an Error Traceback at the bottom auf the page:
Traceback (most recent call last):
File "./prog.py", line 8, in <module>
File "./prog.py", line 3, in func
ValueError: invalid literal for int() with base 10: '1 5 24 2\n'
which showed you that it can't handle your input