All Questions
21 questions
1
vote
2
answers
489
views
.csv TypeError: object of type '_io.TextIOWrapper' has no len() and averaging rows
I have to create a module that reads in an RNA-seq counts table (counts_table.csv) line by line, computes the average number of counts across each gene_ID, and writes the original table contents, in ...
-1
votes
1
answer
144
views
Python list with json saved as a one-String list
I have the following problem:
def guardar_datos_en_json(dato, nombre_archivo):
try:
with open(nombre_archivo, "a") as contenedor:
json.dump(dato, ...
-4
votes
2
answers
46
views
How to assign the first colmn in text file to list variable?
I have txt file which have "strings" like this
5.0125,511.2,5.12.3,4.51212,45.412,54111.5142 \n
4.23,1.2,2.6,2.3,1.2,1.554 \n
How to assign each column a separate list of floats please? I ...
-1
votes
1
answer
31
views
How to read and write to lines in file with python
How do I open a text file which contain several lists with floats only, read each list in this file and then append a new float to one of those lists?
Read text file with lists:
[1.0, 2.0, 3.1] #...
0
votes
0
answers
97
views
get random name from file in python
im a novice at python, i've wrote this those far it needs but i cant get it to run past line 4 the error is a syntax error def fileload filename what am i not doing correctly?
import random
def ...
1
vote
4
answers
94
views
How to sort a list of strings by frequency?
I have a list of files
example_list = [7.gif, 8.gif, 123.html]
There are over 700k elements and I need to sort them by frequency to see the most accessed file and least accessed file.
for i in resl:...
0
votes
1
answer
145
views
How do I count occurrences of a word in a csv file using python?
So for my assignment I was giving a csv file and am supposed to print the number of people in the file, the amount of each type of email (.jp , .uk., etc.) and print the last names in the file that ...
0
votes
3
answers
73
views
Cannot append conditional result to new list
I'm very new to Python or any programming language in general.
For reference:
Assignment
My Code
Question
1.) The assignment for my class is this: read from text file 'word.txt' and write into a ...
0
votes
0
answers
41
views
Line getting replaced instead of getting inserted
I am reading content from a file. I need to insert a line(if not already present) after checking a certain line with a specific keyword(function) and store the function name. I tried inserting it ...
0
votes
3
answers
92
views
Python, removing specific long lines of text in file
I've only programmed in Python for the past 8 months, so please excuse my probably noob approach to python.
My problem is the following, which i hope someone could help me solve.
I have lots of data ...
0
votes
1
answer
32
views
Using data from one file to create two appended lists to a new file
I am trying to take data from one file and create two lists which are both written to a new file. One of the lists contains names 6 characters or less and the second list contains a list with names ...
-1
votes
1
answer
45
views
Files, lists, new-lines, and append()? [duplicate]
I have a file with data:
ABC acd IGK EFG
GHQ ghq acb efg
IJK ijk gtt ttg
I want to split its lines and take some data from each line and join them into a list. Like this:
a = ['acd'...
1
vote
1
answer
684
views
python only writes last output to file
I am trying to write a program that picks a random musical scale until all have been chosen, and the problem I have is that my code is only writing one line to my text file.
I know this is a similar ...
1
vote
3
answers
3k
views
I am trying to read, append and sort all words in a file using Python in TextWrangler application.
Question:
Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each ...
0
votes
2
answers
2k
views
Python 3 How do I append a list in a file?
This is the data my file:
John Smith, 5
Luke Smith, 7
Mary Smith, 8
Boby Smith, 2
I want to be able to add another number onto a specific user in the file. See below (Mary).
John Smith, 5
Luke ...
0
votes
3
answers
7k
views
printing list elements side by side -- file operations
j=0
while j<5:
random_lines=random.choice(men_heroes_lines)
element=(random_lines.split(":")[0:1])
random_lines_women=random.choice(women_heroes_lines)
element_women=...
2
votes
5
answers
107
views
Color Reduction - Only Reds are generated
I am trying to reduce the color of a ppm image file from 255 colors to 5 colors(red, blue, green, black and white). When I initiate my test file, the pixel_list generated is only reds, which is not ...
0
votes
3
answers
1k
views
How to append a list to a file on Python using JSON
I'm getting a bit of a trouble here. I have a text file with ["Data1", "Data2", "Data3"], and I want to make that if data1 is not in the file, then append a new list with all three strings, and if ...
1
vote
1
answer
84
views
Searching for a value and appending if a value exists
Hi i am running a search through a csv file in python 2.7 but im encountering an error in the searching. The file im searching is about 10000 entries long and of the form and here is a sample from the ...
0
votes
2
answers
1k
views
Unix command to append the content of files in a file list
I have a list of 102 file locations in a file. I have to merge the contents of each file in the list into a single file.
Inside the file list, each line consists of one file name.
Please help me a ...
0
votes
1
answer
177
views
faster parsing a file for all list elements and apending into new files based on the list elements
I am trying to parse a log file with threadids in every like. There could be any number of threads that can be configured. All threads write to the same log file and I am parsing the log file and ...