Jupyter notebook tab or space indentation error - jupyter-notebook

# Convert string column to float
def str_column_to_float(dataset, column):
for row in dataset:
row[column] = float(row[column].strip())
print(row[column])
Am trying to create a above function in python using jupyter notebook. But am getting error like below:
File "<ipython-input-5-b591f37367db>", line 5
print(row[column])
^
TabError: inconsistent use of tabs and spaces in indentation
Can anyone help me to fix this?

Make sure the spaces and indentations are proper. The code you have entered should look something like this:

Related

jupyter new-line auto format when cursor between parentheses

When I have my cursor within a set of parentheses in a jupyter notebook and press return, I just get a new line as below, which forces me to go back to the previous line, and hit return again to keep typing:
In other editors like vscode, I get a nice auto-formatted new line with indentation, like this:
Is there a way to get jupyter new line auto formatting like vscode?

How to type '$' in jupyter notebook text cell?

When I try to type $ in the text cell of Jupyter notebook then it is recognized as a special character for math typesetting. How to prevent this? I have tried using '\$' but it doesn't work.
I ran into this some time ago and ended up double escaping it:
\\$test\\$
This will result in $test$
I'm not sure if this is the official way to do it though.

How to add proper spacing in my PSV file?

I have a psv file for some config for my program and it looks really bad. When I save this config from kdb it removes all the white space and it looks like this:
column1|column2|column3
somevalue1|somevalue2|somevalue3
somevalue4|somevalue5|somevalue6
and I want it to look like this when I open it with a text editor like notepad or visual studio code
column1 |column2 |column3
somevalue1 |somevalue2 |somevalue3
somevalue4 |somevalue5 |somevalue6
This psv file has 20000 rows so please don't tell me I have to do this manually.
The reason for which I need to do this spacing is because sometimes my colleagues need to open it to modify just one thing and it is much more readable with the spacing.
I work on linux and I know kdb,python and R so anything in those languages that could help me?
This is quite crude but this q function will take an existing psv file and pad it out:
pad:{m:max each count#''a:flip"|"vs/:read0 x;x 0:"|"sv/:flip m$a}
It works by taking the max string length of each column and padding the rest of the values to the same width using $. The columns are then stitched back together and saved.
Taking this example file contents:
column1|column2|column3
somevalue1|somevalue2|somevalue3
somevalue4|somevalue5|somevalue6
somevalue7|somevalue8|somevalue9
Passing through pad in an open q session:
pad `:sample.psv
Gives the result:
column1 |column2 |column3
somevalue1|somevalue2|somevalue3
somevalue4|somevalue5|somevalue6
somevalue7|somevalue8|somevalue9

How to edit hidden character in String

The appearance of "textparcali" in RStudio Source Editor was as follows.
In textparcali (tbl_df), I ran the following code to delete single strings.
textparcali$word<-gsub("\\W*\\b\\w\\b\\W*",'', textparcali$word)
But the deletion was interesting. You can see the picture below. Please note lines 67 and 50.
Everything was fine for line 50 and lines like that. However, this was not the case for line 67 (and I think there are others like it).
I focused on one line(67) to understand why you deleted it wrong. I've already seen what it says on this line in the editor. But I also wanted to look at the console. I wrote the following code to the console.
textparcali$word[67]
The word on line 67 looks different in the console. The value that doesn't appear when you make a copy paste but surprisingly appears on the console:
The reason I put it as a picture is because this character disappears after the copy-paste command.
You can download the file containing this character from the link below. However, you should open it with Notepad ++.
Character.txt
Gsub did his job right. How is that possible? What's the name of this character? When I try to write code that destroys this character, the " sign changes and does not delete.
textparcali$word<-gsub('[[:punct:]]+',' ',textparcali$word) command also does not work.
What is the explanation of my experience? I do not know. Is there a way to destroy this character? What caused this? I ve asked a lot.
Thank you all.
(I apologize for the bad scribbles in the pictures.)
I found the surprise character.
Above Right, Combining Dot ͘ ͘
The following is the code required to eliminate this character.
c<-"surprise character"
c
[1] "\u0358"
textparcali$word<-gsub("\u0358","",textparcali$word,ignore.case = FALSE)
textparcali$word<-gsub("\u307","",textparcali$word,ignore.case = FALSE)
Code 307 did the job for me. However, you should determine what the actual code is. If not, your character code may be incorrect.
More detailed information can be found in the links below.
https://gist.github.com/ngs/2782436
https://www.charbase.com/0358-unicode-combining-dot-above-right
Thanks a lot!

Terminal of unix can be without square brackets

Can i make look like root#arch$.
Instead if [root#arch~],
I don't like square braces.
Help me if you know i want to remove square[] bracess.
The prompt you're talking about is named PS1, and you can customise its appearance in your .bashrc file.
So edit that file and add something like the following:
PS1="\\u#\\h:\\w"
The next time you log in you should have your new appearance.
PS1="\[\e[1;31m\]\u\[\e[0;15m\]#\\h \\w "
Insert the above code in '~/.bashrc' file, whenever you open a terminal '~/.bashrc' file will be executed hence you get custom prompt.
Tinker with numbers above to get desired colors.

Resources