python Bytes IO usage on AWS Lambda and second iteration of csv fileReplacing spaces with NULL values by comparing two CSV files using pythonHow do I copy a file in Python?Dealing with commas in a CSV fileWhy are Python lambdas useful?Save PL/pgSQL output from PostgreSQL to a CSV fileIn Python, how do I determine if an object is iterable?If Python is interpreted, what are .pyc files?Find all files in a directory with extension .txt in PythonHow do you append to a file in Python?Dump a NumPy array into a csv filePandas writing dataframe to CSV file
Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?
How do I fix the group tension caused by my character stealing and possibly killing without provocation?
What is Cash Advance APR?
Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?
Does Doodling or Improvising on the Piano Have Any Benefits?
Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?
C++ copy constructor called at return
A variation to the phrase "hanging over my shoulders"
How to draw a matrix with arrows in limited space
What (the heck) is a Super Worm Equinox Moon?
Is there any evidence that Cleopatra and Caesarion considered fleeing to India to escape the Romans?
Which Article Helped Get Rid of Technobabble in RPGs?
meaning of encore in this sentence
How would you translate "more" for use as an interface button?
Why Shazam when there is already Superman?
How do I tell my boss that I'm quitting soon, especially given that a colleague just left this week
Is it allowed to activate the ability of multiple planeswalkers in a single turn?
Has any country ever had 2 former presidents in jail simultaneously?
Microchip documentation does not label CAN buss pins on micro controller pinout diagram
Merge org tables
Will number of steps recorded on FitBit/any fitness tracker add up distance in PokemonGo?
Quoting Keynes in a lecture
Mimic lecturing on blackboard, facing audience
Is this part of the description of the Archfey warlock's Misty Escape feature redundant?
python Bytes IO usage on AWS Lambda and second iteration of csv file
Replacing spaces with NULL values by comparing two CSV files using pythonHow do I copy a file in Python?Dealing with commas in a CSV fileWhy are Python lambdas useful?Save PL/pgSQL output from PostgreSQL to a CSV fileIn Python, how do I determine if an object is iterable?If Python is interpreted, what are .pyc files?Find all files in a directory with extension .txt in PythonHow do you append to a file in Python?Dump a NumPy array into a csv filePandas writing dataframe to CSV file
I have a csv file named myref.csv and a list as ref_list:
myref.csv
name,Dept,City
sree,NULL,Bengaluru
vatsasa,,Hyd
,,VJA
capgemini,,TPTY
DTP,,
Bengaluru,NULL,TVM
sre,NULL,MNGL
vatsas,,Kochi
,NULL,TVM
capgemin,NULL,MNGL
DTP9,NULL,Kochi
NULL,NULL,TVM
sree0,NULL,MNGL
ref_list:
ref_list=['Name', 'Dept', 'City', 'Address']
I have following code written:
response = s3.get_object(Bucket=src_bucket, Key=key)
lines = response['Body'].read().splitlines(True)
reader = csv.reader(lines)
first_row = next(reader)
readers=list(reader)
...............
*#done something here using **'readers'**, which is out of scope for this post*
...............
csv_buffer = BytesIO() #Problem has started here..
writer=csv.writer(csv_buffer)
content=csv_buffer.getvalue()
inser_null_at=[]
for i, header in enumerate(ref_list):
if header not in first_row:
inser_null_at.append(i)
writer.writerow(ref_list)
for row in readers:
for i in inser_null_at:
row.insert(i, "")
writer.writerow([item if item != "" else "NULL" for item in row])
I have read myref.csv file through csv.reader and assigned to variable 'reader'. I had written few commands to use 'reader'. But those commands are out of scope for this post.
So as csvfile is iterated once and cannot use the same for second iteration, list format of reader is assigned to another variable named 'readers'.
I would like to check all the columns of list ref_list present in myref.csv.
1. If present, check whether any one of the columns in myref.csv contains spaces. If spaces are present, replace spaces with value NULL and write all the columns to a new csv file, csvfile3, column-wise.
2. If not present, write those missing columns along with existing ones to csvfile3. In addition, values of those missing columns should be shown as NULL in csvfile3, and spaces under existing columns should be replaced with NULL
As i have written on AWS lambda and may be, we need to process huge CSV files, i have created BytesIO() for variable csv_buffer and trying to write the output to that variable. At the end, file will be copied from buffer to an object in a AWS S3 bucket, which is yet to be written.
But the statements starting from csv_buffer = BytesIO() are not executed. So trying to know, where the mistake is done.
Expected Output:
name,Dept,City,Address
sree,NULL,Bengaluru,NULL
vatsasa,NULL,Hyd,NULL
NULL,NULL,VJA,NULL
capgemini,NULL,TPTY,NULL
DTP,NULL,NULL,NULL
Bengaluru,NULL,TVM,NULL
sre,NULL,MNGL,NULL
vatsas,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
capgemin,NULL,MNGL,NULL
DTP9,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
sree0,NULL,MNGL,NULL
Actual Output: None
Note: This has been written on AWS lambda
python amazon-web-services csv aws-lambda
add a comment |
I have a csv file named myref.csv and a list as ref_list:
myref.csv
name,Dept,City
sree,NULL,Bengaluru
vatsasa,,Hyd
,,VJA
capgemini,,TPTY
DTP,,
Bengaluru,NULL,TVM
sre,NULL,MNGL
vatsas,,Kochi
,NULL,TVM
capgemin,NULL,MNGL
DTP9,NULL,Kochi
NULL,NULL,TVM
sree0,NULL,MNGL
ref_list:
ref_list=['Name', 'Dept', 'City', 'Address']
I have following code written:
response = s3.get_object(Bucket=src_bucket, Key=key)
lines = response['Body'].read().splitlines(True)
reader = csv.reader(lines)
first_row = next(reader)
readers=list(reader)
...............
*#done something here using **'readers'**, which is out of scope for this post*
...............
csv_buffer = BytesIO() #Problem has started here..
writer=csv.writer(csv_buffer)
content=csv_buffer.getvalue()
inser_null_at=[]
for i, header in enumerate(ref_list):
if header not in first_row:
inser_null_at.append(i)
writer.writerow(ref_list)
for row in readers:
for i in inser_null_at:
row.insert(i, "")
writer.writerow([item if item != "" else "NULL" for item in row])
I have read myref.csv file through csv.reader and assigned to variable 'reader'. I had written few commands to use 'reader'. But those commands are out of scope for this post.
So as csvfile is iterated once and cannot use the same for second iteration, list format of reader is assigned to another variable named 'readers'.
I would like to check all the columns of list ref_list present in myref.csv.
1. If present, check whether any one of the columns in myref.csv contains spaces. If spaces are present, replace spaces with value NULL and write all the columns to a new csv file, csvfile3, column-wise.
2. If not present, write those missing columns along with existing ones to csvfile3. In addition, values of those missing columns should be shown as NULL in csvfile3, and spaces under existing columns should be replaced with NULL
As i have written on AWS lambda and may be, we need to process huge CSV files, i have created BytesIO() for variable csv_buffer and trying to write the output to that variable. At the end, file will be copied from buffer to an object in a AWS S3 bucket, which is yet to be written.
But the statements starting from csv_buffer = BytesIO() are not executed. So trying to know, where the mistake is done.
Expected Output:
name,Dept,City,Address
sree,NULL,Bengaluru,NULL
vatsasa,NULL,Hyd,NULL
NULL,NULL,VJA,NULL
capgemini,NULL,TPTY,NULL
DTP,NULL,NULL,NULL
Bengaluru,NULL,TVM,NULL
sre,NULL,MNGL,NULL
vatsas,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
capgemin,NULL,MNGL,NULL
DTP9,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
sree0,NULL,MNGL,NULL
Actual Output: None
Note: This has been written on AWS lambda
python amazon-web-services csv aws-lambda
add a comment |
I have a csv file named myref.csv and a list as ref_list:
myref.csv
name,Dept,City
sree,NULL,Bengaluru
vatsasa,,Hyd
,,VJA
capgemini,,TPTY
DTP,,
Bengaluru,NULL,TVM
sre,NULL,MNGL
vatsas,,Kochi
,NULL,TVM
capgemin,NULL,MNGL
DTP9,NULL,Kochi
NULL,NULL,TVM
sree0,NULL,MNGL
ref_list:
ref_list=['Name', 'Dept', 'City', 'Address']
I have following code written:
response = s3.get_object(Bucket=src_bucket, Key=key)
lines = response['Body'].read().splitlines(True)
reader = csv.reader(lines)
first_row = next(reader)
readers=list(reader)
...............
*#done something here using **'readers'**, which is out of scope for this post*
...............
csv_buffer = BytesIO() #Problem has started here..
writer=csv.writer(csv_buffer)
content=csv_buffer.getvalue()
inser_null_at=[]
for i, header in enumerate(ref_list):
if header not in first_row:
inser_null_at.append(i)
writer.writerow(ref_list)
for row in readers:
for i in inser_null_at:
row.insert(i, "")
writer.writerow([item if item != "" else "NULL" for item in row])
I have read myref.csv file through csv.reader and assigned to variable 'reader'. I had written few commands to use 'reader'. But those commands are out of scope for this post.
So as csvfile is iterated once and cannot use the same for second iteration, list format of reader is assigned to another variable named 'readers'.
I would like to check all the columns of list ref_list present in myref.csv.
1. If present, check whether any one of the columns in myref.csv contains spaces. If spaces are present, replace spaces with value NULL and write all the columns to a new csv file, csvfile3, column-wise.
2. If not present, write those missing columns along with existing ones to csvfile3. In addition, values of those missing columns should be shown as NULL in csvfile3, and spaces under existing columns should be replaced with NULL
As i have written on AWS lambda and may be, we need to process huge CSV files, i have created BytesIO() for variable csv_buffer and trying to write the output to that variable. At the end, file will be copied from buffer to an object in a AWS S3 bucket, which is yet to be written.
But the statements starting from csv_buffer = BytesIO() are not executed. So trying to know, where the mistake is done.
Expected Output:
name,Dept,City,Address
sree,NULL,Bengaluru,NULL
vatsasa,NULL,Hyd,NULL
NULL,NULL,VJA,NULL
capgemini,NULL,TPTY,NULL
DTP,NULL,NULL,NULL
Bengaluru,NULL,TVM,NULL
sre,NULL,MNGL,NULL
vatsas,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
capgemin,NULL,MNGL,NULL
DTP9,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
sree0,NULL,MNGL,NULL
Actual Output: None
Note: This has been written on AWS lambda
python amazon-web-services csv aws-lambda
I have a csv file named myref.csv and a list as ref_list:
myref.csv
name,Dept,City
sree,NULL,Bengaluru
vatsasa,,Hyd
,,VJA
capgemini,,TPTY
DTP,,
Bengaluru,NULL,TVM
sre,NULL,MNGL
vatsas,,Kochi
,NULL,TVM
capgemin,NULL,MNGL
DTP9,NULL,Kochi
NULL,NULL,TVM
sree0,NULL,MNGL
ref_list:
ref_list=['Name', 'Dept', 'City', 'Address']
I have following code written:
response = s3.get_object(Bucket=src_bucket, Key=key)
lines = response['Body'].read().splitlines(True)
reader = csv.reader(lines)
first_row = next(reader)
readers=list(reader)
...............
*#done something here using **'readers'**, which is out of scope for this post*
...............
csv_buffer = BytesIO() #Problem has started here..
writer=csv.writer(csv_buffer)
content=csv_buffer.getvalue()
inser_null_at=[]
for i, header in enumerate(ref_list):
if header not in first_row:
inser_null_at.append(i)
writer.writerow(ref_list)
for row in readers:
for i in inser_null_at:
row.insert(i, "")
writer.writerow([item if item != "" else "NULL" for item in row])
I have read myref.csv file through csv.reader and assigned to variable 'reader'. I had written few commands to use 'reader'. But those commands are out of scope for this post.
So as csvfile is iterated once and cannot use the same for second iteration, list format of reader is assigned to another variable named 'readers'.
I would like to check all the columns of list ref_list present in myref.csv.
1. If present, check whether any one of the columns in myref.csv contains spaces. If spaces are present, replace spaces with value NULL and write all the columns to a new csv file, csvfile3, column-wise.
2. If not present, write those missing columns along with existing ones to csvfile3. In addition, values of those missing columns should be shown as NULL in csvfile3, and spaces under existing columns should be replaced with NULL
As i have written on AWS lambda and may be, we need to process huge CSV files, i have created BytesIO() for variable csv_buffer and trying to write the output to that variable. At the end, file will be copied from buffer to an object in a AWS S3 bucket, which is yet to be written.
But the statements starting from csv_buffer = BytesIO() are not executed. So trying to know, where the mistake is done.
Expected Output:
name,Dept,City,Address
sree,NULL,Bengaluru,NULL
vatsasa,NULL,Hyd,NULL
NULL,NULL,VJA,NULL
capgemini,NULL,TPTY,NULL
DTP,NULL,NULL,NULL
Bengaluru,NULL,TVM,NULL
sre,NULL,MNGL,NULL
vatsas,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
capgemin,NULL,MNGL,NULL
DTP9,NULL,Kochi,NULL
NULL,NULL,TVM,NULL
sree0,NULL,MNGL,NULL
Actual Output: None
Note: This has been written on AWS lambda
python amazon-web-services csv aws-lambda
python amazon-web-services csv aws-lambda
asked Mar 7 at 4:31
srivatsasasrivatsasa
127
127
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036134%2fpython-bytes-io-usage-on-aws-lambda-and-second-iteration-of-csv-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036134%2fpython-bytes-io-usage-on-aws-lambda-and-second-iteration-of-csv-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown