1
I have the following file:
es;548
la;1832
primera;35
vez;107
que;2598
hago;15
un;878
pedido;642
y;1713
creo;83
ha;207
funcionado;1
muy;371
bien;257
los;1054
precios;88
fuesen;11
And I’d like to sort it from the numerical column, from the largest to the smallest. I tried that, but it’s not working:
with open ("FREQ.csv", "r") as f:
dados = f.read()
colunas = dados.split(";")
print (sorted (dados[1], key = int, reverse = True))
A CSV file is a file that has a fixed number of columns and multiple rows that follow the same structure. In your case it seems to be just a text file with only one line that has data separated by a semicolon. You can ask the question an example of the correct output of this file line?
– Pagotti
That’s right. He placed only one line of the CSV file.
– Reginaldo Rigo
But what you meant by 'is not working', which, in fact, happens?
– Reginaldo Rigo
I have this message: /usr/bin/python3.5 /home/Janaina/Bureau/Lexique/Python/sort_freq.py Traceback (Most recent call last): File "/home/Janaina/Bureau/Lexique/Python/sort_freq.py", line 7, in <module> print (data[1], key = int, Reverse = True)) Valueerror: invalid literal for int() with base 10: ’s' Process finished with Exit code 1
– pitanga
@Pagotti I have exactly one CSV file (I didn’t create it), the problem is I can’t put it here the way it is (two columns).
– pitanga
@Pitanga you don’t need to put the exact file in the question. Just update the question with an example of data (can be 2 lines from the file) and an example of how you expect the output to be. The way you’re putting it is confusing.
– Pagotti