All Questions
1,162 questions
0
votes
2
answers
1k
views
Convert multiple .txt files to .csv files
I have multiple .txt files and I want to convert them to .csv files with the same name. The filename for these .txt files is something like this:
01-09-2022-something.txt
02-09-2022-something.txt
03-...
0
votes
1
answer
99
views
Write a list of lists into csv and having UnicodeEncodeError in python
I am converting an xlsm file to csv using the openpyxl library.
I have the problem that when I try to pass the list of lists to the csv python returns the following error:
Traceback (most recent call ...
1
vote
2
answers
267
views
Saving data in excel by cell rather than semi-colon with python
***Edit: I am originally saving the code to a .csv file but then later converting it to a .xlsx file.
I am trying to change my code to save the values in separate cells verses in the same cell ...
0
votes
0
answers
34
views
Interpret CSV with equal delimiter values in Python 2.7
I need to create the following solution, I have a CSV file that the delimiter is a comma (,), but in one of the columns this comma can come by error in the user registration. The CSV scenario is this:
...
2
votes
3
answers
511
views
Zipping a list of folders with Python
everyone. I'm really new to Python, so I need some help here.
I have a list of folders names inside a .CSV file. All these folders are inside the same path.
I need to zip them individually (each one ...
0
votes
0
answers
90
views
How to load certain portion of file into memory and write it on a file in Python?
I have a csv file which generates dataframe for every second and stores it in it. It will have millions of values. How to load only certain part. Like only first 5 MB. Then next 5 MB in a text file.. ...
0
votes
1
answer
444
views
Compare 2 csv files and check for first 2 columns, if it matches ask the user to decide to override or not and then proceed to next row
I have a use case where I have 2 CSV files with some rows in each CSV file, and they have three columns each. Compare the 2 csv files for first 2 columns and if it matches then ask the user input if ...
0
votes
1
answer
30
views
Please help me out with translating this Python code [duplicate]
Please help with translate this Python code
I am trying to figure out the meaning of this code and could not end up with a conclusion... does anybody know how this single line code is like when it is ...
0
votes
1
answer
549
views
Add random noise in each value of CSV rows
I am trying to add some random noise to my csv columns except last column.
This is my csv file:
z-1 z-2 z-3 z-4 z-5 z-6 z-7 class
0.1305512 0....
0
votes
0
answers
74
views
Python read csv file
Help me! This is the error message
UnicodeDecodeError
Traceback (most recent call last)
<ipython-input-8-6e197d6c2788> in <module>()
2 csv_reader = csv.reader(f)
3
----> ...
0
votes
1
answer
732
views
How to insert values based on condition in column in the CSV file using Python?
I want to insert values from the list based on the condition,
For example, Please find below my algorithm of the code using CSV module.
out_file = open("c://Project//in.csv", "w")
...
1
vote
2
answers
536
views
Replace xml value based on csv columns
I am trying to replace class name in xml file based on csv columns. Actually xml files are annotation files.
This is the format of xml:
<annotation>
<folder>./test_xmls</folder>
<...
0
votes
1
answer
110
views
How can i query csv file and update a value
I'm working with python 2.7 and basically my python script consist of opening a csv file, looping into the rows to find the one with the id the user entered. Once the row is found, depending on some ...
1
vote
1
answer
1k
views
Python - CSV rows into multiple lists
I want to convert each of the rows in my csv file into lists. But the below code doesn't work , it rather converts all the columns into lists
def data():
import csv
f=open("mydata.csv",&...
0
votes
1
answer
498
views
converting a multiple space delimited file to CSV using python 2.7 with Pandas?
I have multiple problems that I'm trying to solve with this single file, but but my immediate concern is trying to convert this file which has fields which are delimited by variable numbers of white ...
0
votes
2
answers
247
views
In python how to load a pipe delimited file into csv file after a occurrence of a text?
I have a file which goes something like this:
Date: 05/20/2020
Age: 25
Gender: male
Convert to csv:
Apples|7|monday|texas
Oranges|9|thursday|california
Peaches|12|Monday|kansas
...
0
votes
1
answer
581
views
How to rename csv files and change name with each loop iteration?
How do I change name for each csv file? I am getting new data for each token. Also can I give the csv files, the real name of token?
Example:
Token 492033 = kotakbank.csv, 738561 = reliance.csv, ...
-1
votes
1
answer
166
views
Append to csv file column-wise under one header
Coding in Python 2.7. I have a csv file already present called input.csv. In that file we have 3 headers — Filename, Category, Version — under which certain values already exist.
I want to know how I ...
1
vote
0
answers
116
views
Multiline CSV read using Python3
Everyday we get CSV file from vendor and we need to parse them and insert it to database. We use single Python3 program for all the tasks.
The problem happening is with multiline CSV files, where the ...
0
votes
3
answers
143
views
Continue to run the Python code however the value of CSV cell is null
I have a csv file with below format as a sample, as you see it is possible to have one message or 2 messages,
Sara,27,Message1,Message2
Joe,21,Message3
I write my reader as below, It works fine with ...
-3
votes
2
answers
511
views
Filter JSON data into a CSV list
My goal is to take the host names out of this JSON file (output.json) and put them into a CSV list (newoutput.csv) using python, with the end result looking like:
TheHost1, TheHost2, TheHost3
There ...
0
votes
1
answer
50
views
error reading csv file using panda python
import pandas
from bs4 import BeautifulSoup
import requests
df_list = []
path = "C:/Users/bubai/Desktop/try/scrapy/output"
for file in os.listdir(path):
df_list.append(path + '/' + file)
...
1
vote
2
answers
1k
views
reading multiple csv file from a different directory in python
import csv
import pandas
df_list = []
path = "C:/Users/bubai/Desktop/try/scrapy/output"
#all csv file
for file in os.listdir(path):
#print(file)
df_list.append(file) # all csv file in this
#...
1
vote
1
answer
513
views
Why is ^M added to the last line of an output file written in Python 2.7?
This is the file I have, a.tsv
ENST00000330436 chr4 - 96099729 96125021
ENST00000332884 chr4 - 96518062 96549623
ENST00000651514 chr5 - 145620969 ...
0
votes
2
answers
94
views
with python from csv to text files
I am trying to wrtie two txtfiles ( Test_8.txt and Test_9.txt ) from the csvfile.
From row COL4 i am getting single and double quotes and '['.
how can i get rid of them?
csvfie:
NR;COL1;COL2;COL3;...
0
votes
0
answers
67
views
UnicodeEncodeError while writing Dict to CSV
following error: "UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 2: ordinal not in range(128)"
mydict = {
'SNo': ['1','2','3'],
'Name': ['Dinesh', '...
0
votes
2
answers
60
views
How to convert a dictionary and write it into a CSV file?
#!/bin/python
import csv
my_dict = {'Age': ['22', '23', '34'], 'Name': ['Dinesh', 'Suresh', 'Mahesh']}
print(my_dict)
with open('Names.csv', 'w') as f:
fieldnames = ['Age', 'Name']
writer =...
0
votes
2
answers
1k
views
How can I compare the rows of two CSV files based on the similarities in them?
file1.csv looks like:
file2.csv looks like:
The desired output is "updated file2.csv":
file1.csv is to be taken as reference and shouldn't be altered.
The rows in file2.csv should be rearranged ...
-2
votes
1
answer
68
views
CSV file reading problem (not using CSV module), program not offering option for input where it should
I need help with the first section of the program, where I am trying to create a condition which will only offer the user the option to input a province if the selected country has a province listed ...
0
votes
2
answers
1k
views
How do I write a custom CSV Reader in python without using csv import?
I'm trying to solve a problem from the pyschools website that asks to write a script that reads a CSV file with comas "," as a delimiter and returns a list of records. When running my script on their ...
-1
votes
1
answer
179
views
How to fill null values in a column?
I need to read a csv file and fill the empty/null values in column "Phone,Email,address,city,state,Zip" based on the relationshiptype and LastName and write to a new csv file.
Example: If a person ...
-1
votes
1
answer
31
views
How to convert a csv format values inside a dict to JSON format in python?
I know how to convert the csv file and extract the datas. But this is something different, I get the values from the database as in csv format and I need to convert for JSON format.
Current Output:
...
0
votes
2
answers
53
views
How can I use a CSV file in python?
When I did it using an online tutorial, it kept telling me that there was an error with quotations, but after editing, I still don't see the problem. CAn you please help?
import csv
with open("...
0
votes
1
answer
2k
views
Read csv with boxed question marks
I have CSV file(in French) that has rows of text that look like :
"Vend, 21 sept, 2018","43326370894332743328177832888443325333815370","NX","651-2141652-1309NON666-3778692-2229581-300-6525622-...
-1
votes
1
answer
3k
views
How to fill null values in a column in a csv file?
I need read a csv file and fill the empty/null values in column "Phone and Email" based on the person's address and write to a new csv file. Ex: if a person "Jonas Kahnwald" doesn't have the phone ...
1
vote
1
answer
65
views
Python 2.7: Remove duplicates from csv based on conditions
I have a csv file that has the following format:
Username,Name,Phone,Email,Country,Login
John23,John Doe,99999999,[email protected],Italy,1585589097.787715
John23,John Doe,99999999,[email protected],...
2
votes
0
answers
41
views
Python swallows the first value that comes in through serial communication
I have an Nodemcu ESP8266 connected to my Raspberry Pi over a serial connection. The Nodemcu is frequently (every 5 min.) sending data to my Pi, but if I don't run the script on my Pi this data is not ...
-2
votes
1
answer
50
views
Creating a JSON out of a .txt file using Python
This is what the data looks like in the txt file (tab delimited):
President, U.S. Vote For 1 0 of 1,599 precincts reporting
Candidate Party Votes
Deval Patrick DEM 0
Bernie Sanders DEM 0
...
-2
votes
1
answer
99
views
How to read a csv and write to a new CSV
python 2.7
input csv file
person alpha beta gamma
alex 1 2
bob 2 1
zac 1 2
output format
Person data qty<2
alex beta,gamma ...
0
votes
1
answer
220
views
CSV reader incorrectly returns first element of line
I'm using python to read a CSV file with the following settings:
import unicodecsv, ssl
ctx = ssl._create_unverified_context()
response = urllib2.urlopen(url, timeout=300, context=ctx)
...
0
votes
1
answer
126
views
Update only two columns from one CSV file to another CSV file
I have two files, the first one is called first.csv, and looks like this:
header1,header2
1,a
2,b
The second file is called second.csv, and looks like this:
header1,header2,header3,header4,header5
...
1
vote
1
answer
301
views
Parsing in memory CSV files from zip archives
I'm working on a new library which will allow the user to parse any file (xlsx, csv, json, tar, zip, txt) into generators.
Now I'm stuck at zip archive and when I try to parse a csv from it, I get
io....
0
votes
1
answer
91
views
Failing to Convert Files from CSV to Excel
Attempting to convert a folder list of csv files to excel. Unfortunately most of them do not work and I also get following errors. When I do the same via excel front end, it works fine to save them ...
1
vote
0
answers
616
views
Python : How to update a row if it exists else make an Insert in a CSV file
I am trying to perform the below operations in python 2.7.
If CSV file (test.csv) doesn't exist, create one else append.
Insert or Update the CSV file
File contents:
111,03/11/2019,ABC
112,04/11/...
0
votes
1
answer
53
views
Python: Failed in retrieving the highest amount from a repeated data with different amount in a certain year
The csv file that I have contain several repeated supplier_name but with different amt for year 2015-2017.
Here goes my codes.
df = pd.read_csv('government-procurement-via-gebiz.csv', parse_dates=['...
0
votes
2
answers
745
views
How to update a csv file without appending new rows using python?
I have a power shell script and python script which writes data into one common CSV file. If I used the keyword 'w+' in python script it deletes the old data and replaces with new data. If I use ...
0
votes
0
answers
210
views
getting tweets written in sinhala language and saving in csv file
The below part of code fetches all tweets for a specific user and stores them into a CSV file. when I convert tweets written in sinhala language to CSV, Sinhala language characters are not visible ...
1
vote
2
answers
58
views
How do i uniquely identify a row in a csv by a column value, and then later check another column for a "Passed" keyword and print it
I have a CSV File,
APIName_UniqueId,TC_Status,Comment
123456,PASSED,API "123456_Get Download Credential_1" is PASSED
123457,PASSED,API "123457_Get Upload Credential_1" is PASSED
I want to check ...
2
votes
1
answer
239
views
How to split csv rows containing multiple string values based on comma but without considering comma inside curly brackets { }
I am reading one csv file and trying to split its rows based on comma, Here in my case rows containing some values having comma as a part of that value and that value start and ends with { }.
My ...
0
votes
2
answers
1k
views
Write filtered json values to csv
I am looping through a json line files where i am just filtering for sender id and status nd outputting this to the terminal. There are multiple_sender id which are within a list whilst the sender is ...