I use google-spreadsheets,I want to copy python code to google-spreadsheets,but I find google-spreadsheets automatically cancels the code's indentation.
My code:
import pandas as pd
import csv
rs = pd.read_csv(r'D:/Clustering_TOP.csv',encoding='utf-8')
with open('D:/Clustering_TOP.csv','r') as csvfile:
reader = csv.reader(csvfile)
rows = [row for row in reader]
csv_title = rows[0]
csv_title = csv_title[1:]
len_csv_title = len(csv_title)
for i in range(len_csv_title):
for j in range(i+1):
print(str(csv_title[j])+'_'+str(csv_title[i]) + " = " + str(rs[csv_title[i]].corr(rs[csv_title[j]])), end='\t')
print()
When I paste the code to google-docs,the code turns into this:
And there is no indentation in the paste option.
How can I keep the indentation of the code?
How about this workaround? In your title, we can see how to recover?. Do you want to add the indentation to the script without indentation which had already been pasted? Or when you paste the script, do you want to keep the indentation? If in the case of later, I think that there are 2 patterns. If the situation is the later, please choose one of 2 patterns. I think that there are several workarounds. So please think of this as one of them.
Pattern 1
Paste the script with line by line.
Pattern 2
Paste the script in the cell "A1".
Paste this formula in the cell "A2".
=TRANSPOSE(SPLIT(A1, char(10)))
You can retrieve only the script with the indentation by copying values and pasting as values only.
If this was not what you want, I'm sorry.
Related
I am trying to use a program to speed up a repetitive Stata task. This is the first part of my program:
program alphaoj
syntax [varlist] , using(string) occ_level(integer) ind_level(integer)
import excel `using', firstrow
display "`using'"
split "`using'", parse(_)
local year = `2'
display "`year'"
display `year'
When I run this program, using the line alphaoj, ind_level(4) occ_level(5) using("nat4d_2002_dl.xls"), I receive the error factor-variable and time-series operators not allowed r(101);
I am not quite sure what is being treated as a factor or time series operator.
I have replaced the split line with tokenize, and the parse statement with parse("_"), and I continue to run into errors. In that case, it says _ not found r(111);
Ideally, I would have it take the year from the filename and use that year as the local.
I am struggling with how I should perform this seemingly simple task.
An error is returned because the split command only accepts string variables. You can't pass a string directly to it. See help split for more details.
You can achieve your goal of extracting the year from the filename and storing that as a local macro. See below:
program alphaoj
syntax [varlist], using(string)
import excel `using', firstrow
gen stringvar = "`using'"
split stringvar, parse(_)
local year = stringvar2
display `year'
end
alphaoj, using("nat4d_2002_dl.xls")
The last line prints "2002" to the console.
Alternative solution that avoids creating an extra variable:
program alphaoj
syntax [varlist], using(string)
import excel `using', firstrow
local year = substr("`using'",7,4)
di `year'
end
alphaoj, using("nat4d_2002_dl.xls")
Please note that this solution is reliant on the Excel files all having the exact same character structure.
Given the following text
Node1_L1
Node1_L2
Node2_L2
Node2_L1
Node3_L2
Node1_L3
Node2_L3
Node4_L2
Node3_L3
Node4_L3
Node3_L1
Node5_L2
Node6_L2
I can use vscode's built-in folding feature to fold it to look like so
+ Node1_L1
Node2_L1
+ Node3_L2
+ Node4_L2
Node3_L1
Node5_L2
Node6_L2
but when I now select the folded text and copy & paste it then it actually grabbed all text - also the hidden one. The result of copy & paste of the first 4 lines of the folded text above would therefore be
Node1_L1
Node1_L2
Node2_L2
Node2_L1
Node3_L2
Node1_L3
Node2_L3
Node4_L2
whereas I would like to have
Node1_L1
Node2_L1
Node3_L2
Node4_L2
Hope that makes sense and someone knows a way to do it. Thanks!
Maybe there is another way of doing it but a workaround seems to be using block selection with multiple cursors - see the GIF
If the selection doesn't include the new line and carriage return, folded content will not be copied.
The selection must go to the start of the next line to select the folded text ( hidden text )
https://github.com/Microsoft/vscode/issues/41922#issuecomment-359368290
The op actually wants to select 'unfolded' text ignoring the folded text so they need to use a multi-line select where each selection will span a single line
I want to copy a table from iPython notebook into a Word doc. I'm using Word for Mac 2011. The table is a standard pandas output and looks like this:
If I use Apple+C to copy the table, and then paste it into a Word doc, I get this:
Surely there must be an easier way?
Creating a table with the same number of rows/columns in Word and then trying to paste the cells there doesn't work either.
I guess I could screenshot the table, but I'd like to include the raw data in the document if possible.
The problem in this case (from the Word perspective) is not the table layout - it's the paragraph layout. Each paragraph has a substantial indent on right and left, and more space before/after than you would normally want.
I don't think any of the Paste options (e.g. Paste Special) in Word is going to help, unless you paste as unformatted text, then select the text, convert to a table, then proceed from there.
But, even a simple Word VBA macro such as this one will leave you with something a bit more manageable. (Select a table you copied in, then run the macro). A little bit more work on the code would probably allow you to get most of the formatting you want, most of the time.
Sub fixupSelectedTable()
With Selection.Tables(1).Range.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceSingle
End With
End Sub
If you are more familiar with Applescript, the equivalent looks something like this:
-- you may need to fix up the application name
-- (I use this to ensure that the script uses the Open Word 2011 doc
-- and does not try to start Word for Mac 15 (2016))
tell application "/Applications/Microsoft Office 2011/Microsoft Word.app"
tell the paragraph format of the text object of table 1 of the text object of the selection
set paragraph format left indent to 0
set paragraph format right indent to 0
set space before to 0
set space after to 0
set line spacing rule to line space single
end tell
end tell
I'm using FastqGeneralIterator, but I find that it removes the # from the 1st line of a fastq file and also the information for the 3rd line (it removes the entire 3rd line).
I added the # in the 1st line in the following way:
for line in open("prova_FiltraN_CE_filt.fastq"):
fout.write(line.replace('SEQ', '#SEQ'))
I want to add also the 3rd line, that starts with + and there is nothing after that. For example:
#SEQILMN0
TCATCGTA....
+
#<BBBFFF.....
Can someone help me?
you can use, String Formatting Operations %
from Bio.SeqIO.QualityIO import FastqGeneralIterator
with open("prova_FiltraN_CE_filt.fastq", "rU") as handle:
for (title, sequence, quality) in FastqGeneralIterator(handle):
print("#%s\n%s\n+\n%s" % (title, sequence, quality))
you get fastq print format, using FastqGeneralIterator
#SEQILMN0
TCATCGTA....
+
#<BBBFFF....
Here is a simple lists where I like to change the numbers: the entries are as below and it got over 300 entries like it
tom112
smith113
harry114
linda115
cindy106
samantha147
It need to be changed to
tom212
smith213
harry214
...and so on.
Please assist using notepad++ regular expression.
Thanks.
Assuming it's just a matter of replacing a name followed by a number starting with 1 with the same number but starting with 2 instead:
Ctrl + H for search & replace.
Check Regular expression under Search Mode.
Next to Find what type or copy in ([a-zA-Z]+)1([0-9]+).
Next to Replace with type or copy in \12\2.
Click Replace All and that should do it.
Add any other characters that might appear in the name before the number inside the first set of brackets with a-zA-Z.