Python 3 -Printing to console in spreadsheet format so I can cut and paste columns
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
As described on the title I would like to print to the console two or more columns of strings so that I can copy and paste into a goog sheet and it will maintain the column separation format(ie one word per cell). I tried printing strings separated by a tab to no avail. I do not want to write to csv with a module.
Thanks
python csv
add a comment |
As described on the title I would like to print to the console two or more columns of strings so that I can copy and paste into a goog sheet and it will maintain the column separation format(ie one word per cell). I tried printing strings separated by a tab to no avail. I do not want to write to csv with a module.
Thanks
python csv
Could you paste your current work?
– Kevin Fang
Jan 4 at 4:46
Can you please provide an example of what you've tried so far?
– Nick Perkins
Jan 4 at 4:52
Just load csv into pandas dataframe and print it you will get better format
– Pavan Kumar T S
Jan 4 at 5:10
1
The problem is with your sheet programs. Both excel and google sheets have text to columns -feature, which can properly sort your text using almost any delimiter you want. In google sheets you can find it from "data:Split text to columns" menu. In excel it's in "data:text to columns"
– Stacking For Heap
Jan 4 at 5:15
@StackingForHeap, thanks, did not know about that feature.
– rearThing
Jan 4 at 19:48
add a comment |
As described on the title I would like to print to the console two or more columns of strings so that I can copy and paste into a goog sheet and it will maintain the column separation format(ie one word per cell). I tried printing strings separated by a tab to no avail. I do not want to write to csv with a module.
Thanks
python csv
As described on the title I would like to print to the console two or more columns of strings so that I can copy and paste into a goog sheet and it will maintain the column separation format(ie one word per cell). I tried printing strings separated by a tab to no avail. I do not want to write to csv with a module.
Thanks
python csv
python csv
asked Jan 4 at 4:43
rearThingrearThing
1391216
1391216
Could you paste your current work?
– Kevin Fang
Jan 4 at 4:46
Can you please provide an example of what you've tried so far?
– Nick Perkins
Jan 4 at 4:52
Just load csv into pandas dataframe and print it you will get better format
– Pavan Kumar T S
Jan 4 at 5:10
1
The problem is with your sheet programs. Both excel and google sheets have text to columns -feature, which can properly sort your text using almost any delimiter you want. In google sheets you can find it from "data:Split text to columns" menu. In excel it's in "data:text to columns"
– Stacking For Heap
Jan 4 at 5:15
@StackingForHeap, thanks, did not know about that feature.
– rearThing
Jan 4 at 19:48
add a comment |
Could you paste your current work?
– Kevin Fang
Jan 4 at 4:46
Can you please provide an example of what you've tried so far?
– Nick Perkins
Jan 4 at 4:52
Just load csv into pandas dataframe and print it you will get better format
– Pavan Kumar T S
Jan 4 at 5:10
1
The problem is with your sheet programs. Both excel and google sheets have text to columns -feature, which can properly sort your text using almost any delimiter you want. In google sheets you can find it from "data:Split text to columns" menu. In excel it's in "data:text to columns"
– Stacking For Heap
Jan 4 at 5:15
@StackingForHeap, thanks, did not know about that feature.
– rearThing
Jan 4 at 19:48
Could you paste your current work?
– Kevin Fang
Jan 4 at 4:46
Could you paste your current work?
– Kevin Fang
Jan 4 at 4:46
Can you please provide an example of what you've tried so far?
– Nick Perkins
Jan 4 at 4:52
Can you please provide an example of what you've tried so far?
– Nick Perkins
Jan 4 at 4:52
Just load csv into pandas dataframe and print it you will get better format
– Pavan Kumar T S
Jan 4 at 5:10
Just load csv into pandas dataframe and print it you will get better format
– Pavan Kumar T S
Jan 4 at 5:10
1
1
The problem is with your sheet programs. Both excel and google sheets have text to columns -feature, which can properly sort your text using almost any delimiter you want. In google sheets you can find it from "data:Split text to columns" menu. In excel it's in "data:text to columns"
– Stacking For Heap
Jan 4 at 5:15
The problem is with your sheet programs. Both excel and google sheets have text to columns -feature, which can properly sort your text using almost any delimiter you want. In google sheets you can find it from "data:Split text to columns" menu. In excel it's in "data:text to columns"
– Stacking For Heap
Jan 4 at 5:15
@StackingForHeap, thanks, did not know about that feature.
– rearThing
Jan 4 at 19:48
@StackingForHeap, thanks, did not know about that feature.
– rearThing
Jan 4 at 19:48
add a comment |
1 Answer
1
active
oldest
votes
It is difficult to answer this question without knowing the exact format of the text you are trying to format. But here is an example of what you can do if your text is stored in a list of lists representing rows of data:
In [9]: def delimited(delimiter, text):
...: for i in text:
...: print(delimiter.join(i))
...:
In [10]: foo = [['a','b','c'],['d','e','f'],['g','h','i']]
In [11]: delimited(' ', foo)
Prints:
a b c
d e f
g h i
Now you can paste it that into a Google Sheet and it should automatically detect the line breaks and paste the data into separate rows. Now select the column containing your data, and click on Data in the menu bar, followed by Split Text to Columns... Google should autodetect the spaces as delimiters and split your data into separate columns. Otherwise, you can even try passing different delimiters into the function above, e.g. comma, semi-colon, etc. and then specifying the delimiter in your Google Sheet after clicking Split Text to Columns...
Thanks Aryan. In this respect you did provide A solution which I am likely to use(formatting in google sheet rather then python). It would be nice to know from the experts if there is indeed a way to do it. I looked into prettyprint but nothing there jumped to focus. I'll wait some time before marking your answer. Thanks.
– rearThing
Jan 4 at 19:40
add a comment |
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%2f54033226%2fpython-3-printing-to-console-in-spreadsheet-format-so-i-can-cut-and-paste-colum%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is difficult to answer this question without knowing the exact format of the text you are trying to format. But here is an example of what you can do if your text is stored in a list of lists representing rows of data:
In [9]: def delimited(delimiter, text):
...: for i in text:
...: print(delimiter.join(i))
...:
In [10]: foo = [['a','b','c'],['d','e','f'],['g','h','i']]
In [11]: delimited(' ', foo)
Prints:
a b c
d e f
g h i
Now you can paste it that into a Google Sheet and it should automatically detect the line breaks and paste the data into separate rows. Now select the column containing your data, and click on Data in the menu bar, followed by Split Text to Columns... Google should autodetect the spaces as delimiters and split your data into separate columns. Otherwise, you can even try passing different delimiters into the function above, e.g. comma, semi-colon, etc. and then specifying the delimiter in your Google Sheet after clicking Split Text to Columns...
Thanks Aryan. In this respect you did provide A solution which I am likely to use(formatting in google sheet rather then python). It would be nice to know from the experts if there is indeed a way to do it. I looked into prettyprint but nothing there jumped to focus. I'll wait some time before marking your answer. Thanks.
– rearThing
Jan 4 at 19:40
add a comment |
It is difficult to answer this question without knowing the exact format of the text you are trying to format. But here is an example of what you can do if your text is stored in a list of lists representing rows of data:
In [9]: def delimited(delimiter, text):
...: for i in text:
...: print(delimiter.join(i))
...:
In [10]: foo = [['a','b','c'],['d','e','f'],['g','h','i']]
In [11]: delimited(' ', foo)
Prints:
a b c
d e f
g h i
Now you can paste it that into a Google Sheet and it should automatically detect the line breaks and paste the data into separate rows. Now select the column containing your data, and click on Data in the menu bar, followed by Split Text to Columns... Google should autodetect the spaces as delimiters and split your data into separate columns. Otherwise, you can even try passing different delimiters into the function above, e.g. comma, semi-colon, etc. and then specifying the delimiter in your Google Sheet after clicking Split Text to Columns...
Thanks Aryan. In this respect you did provide A solution which I am likely to use(formatting in google sheet rather then python). It would be nice to know from the experts if there is indeed a way to do it. I looked into prettyprint but nothing there jumped to focus. I'll wait some time before marking your answer. Thanks.
– rearThing
Jan 4 at 19:40
add a comment |
It is difficult to answer this question without knowing the exact format of the text you are trying to format. But here is an example of what you can do if your text is stored in a list of lists representing rows of data:
In [9]: def delimited(delimiter, text):
...: for i in text:
...: print(delimiter.join(i))
...:
In [10]: foo = [['a','b','c'],['d','e','f'],['g','h','i']]
In [11]: delimited(' ', foo)
Prints:
a b c
d e f
g h i
Now you can paste it that into a Google Sheet and it should automatically detect the line breaks and paste the data into separate rows. Now select the column containing your data, and click on Data in the menu bar, followed by Split Text to Columns... Google should autodetect the spaces as delimiters and split your data into separate columns. Otherwise, you can even try passing different delimiters into the function above, e.g. comma, semi-colon, etc. and then specifying the delimiter in your Google Sheet after clicking Split Text to Columns...
It is difficult to answer this question without knowing the exact format of the text you are trying to format. But here is an example of what you can do if your text is stored in a list of lists representing rows of data:
In [9]: def delimited(delimiter, text):
...: for i in text:
...: print(delimiter.join(i))
...:
In [10]: foo = [['a','b','c'],['d','e','f'],['g','h','i']]
In [11]: delimited(' ', foo)
Prints:
a b c
d e f
g h i
Now you can paste it that into a Google Sheet and it should automatically detect the line breaks and paste the data into separate rows. Now select the column containing your data, and click on Data in the menu bar, followed by Split Text to Columns... Google should autodetect the spaces as delimiters and split your data into separate columns. Otherwise, you can even try passing different delimiters into the function above, e.g. comma, semi-colon, etc. and then specifying the delimiter in your Google Sheet after clicking Split Text to Columns...
answered Jan 4 at 5:15
Aryan JainAryan Jain
162
162
Thanks Aryan. In this respect you did provide A solution which I am likely to use(formatting in google sheet rather then python). It would be nice to know from the experts if there is indeed a way to do it. I looked into prettyprint but nothing there jumped to focus. I'll wait some time before marking your answer. Thanks.
– rearThing
Jan 4 at 19:40
add a comment |
Thanks Aryan. In this respect you did provide A solution which I am likely to use(formatting in google sheet rather then python). It would be nice to know from the experts if there is indeed a way to do it. I looked into prettyprint but nothing there jumped to focus. I'll wait some time before marking your answer. Thanks.
– rearThing
Jan 4 at 19:40
Thanks Aryan. In this respect you did provide A solution which I am likely to use(formatting in google sheet rather then python). It would be nice to know from the experts if there is indeed a way to do it. I looked into prettyprint but nothing there jumped to focus. I'll wait some time before marking your answer. Thanks.
– rearThing
Jan 4 at 19:40
Thanks Aryan. In this respect you did provide A solution which I am likely to use(formatting in google sheet rather then python). It would be nice to know from the experts if there is indeed a way to do it. I looked into prettyprint but nothing there jumped to focus. I'll wait some time before marking your answer. Thanks.
– rearThing
Jan 4 at 19:40
add a comment |
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%2f54033226%2fpython-3-printing-to-console-in-spreadsheet-format-so-i-can-cut-and-paste-colum%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
Could you paste your current work?
– Kevin Fang
Jan 4 at 4:46
Can you please provide an example of what you've tried so far?
– Nick Perkins
Jan 4 at 4:52
Just load csv into pandas dataframe and print it you will get better format
– Pavan Kumar T S
Jan 4 at 5:10
1
The problem is with your sheet programs. Both excel and google sheets have text to columns -feature, which can properly sort your text using almost any delimiter you want. In google sheets you can find it from "data:Split text to columns" menu. In excel it's in "data:text to columns"
– Stacking For Heap
Jan 4 at 5:15
@StackingForHeap, thanks, did not know about that feature.
– rearThing
Jan 4 at 19:48