Latex expressions in pandas dataframes not rendering in vscode
I am trying to set some labels and the caption of my dataframe using mathjax, but it doesn't render in vscode.
For example, when I do
import pandas as pd
test = pd.DataFrame(index=["$\sigma$"])
test
I get this as output in my jupyter notebook:
$\sigma$
Instead of the letter σ. I get the right results if I do the same thing in JupyterLab (in Google Chrome).
Note: Other packages that use mathjax seem to be working fine. Printing latex expressions in matplotlib, sympy and even cells marked with '%%latex' work fine.
do you know?
how many words do you know
See also questions close to this topic
-
Any efficient way to compare two dataframes and append new entries in pandas?
I have new files which I want to add them to historical table, before that, I need to check new file with historical table by comparing its two column in particular, one is
state
and another one isdate
column. First, I need to checkmax (state, date)
, then check those entries withmax(state, date)
in historical table; if they are not historical table, then append them, otherwise do nothing. I tried to do this in pandas bygroup-by
on new file and historical table and do comparison, if any new entries from new file that not in historical data, then add them. Now I have issues to append new values to historical table correctly in pandas. Does anyone have quick thoughts?My current attempt:
import pandas as pd src_df=pd.read_csv("https://raw.githubusercontent.com/adamFlyn/test_rl/main/src_df.csv") hist_df=pd.read_csv("https://raw.githubusercontent.com/adamFlyn/test_rl/main/historical_df.csv") picked_rows = src_df.loc[src_df.groupby('state')['yyyy_mm'].idxmax()]
I want to check
picked_rows
inhist_df
where I need to check bystate
andyyyy_mm
columns, so only add entries frompicked_rows
wherestate
hasmax
value or recent dates. I created desired output below. I tried inner join orpandas.concat
but it is not giving me correct out. Does anyone have any ideas on this?Here is my desired output that I want to get:
import pandas as pd desired_output=pd.read_csv("https://raw.githubusercontent.com/adamFlyn/test_rl/main/output_df.csv")
-
How to bring data frame into single column from multiple columns in python
I have data format in these multiple columns. So I want to bring all 4 columns of data into a single column.
YEAR Month pcp1 pcp2 pcp3 pcp4 1984 1 0 0 0 0 1984 2 1.2 0 0 0 1984 3 0 0 0 0 1984 4 0 0 0 0 1984 5 0 0 0 0 1984 6 0 0 0 1.6 1984 7 3 3 9.2 3.2 1984 8 6.2 27.1 5.4 0 1984 9 0 0 0 0 1984 10 0 0 0 0 1984 11 0 0 0 0 1984 12 0 0 0 0
-
Exclude Japanese Stopwords from File
I am trying to remove Japanese stopwords from a text corpus from twitter. Unfortunately the frequently used nltk does not contain Japanese, so I had to figure out a different way.
This is my MWE:
import urllib from urllib.request import urlopen import MeCab import re # slothlib slothlib_path = "http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt" sloth_file = urllib.request.urlopen(slothlib_path) # stopwordsiso iso_path = "https://raw.githubusercontent.com/stopwords-iso/stopwords-ja/master/stopwords-ja.txt" iso_file = urllib.request.urlopen(iso_path) stopwords = [line.decode("utf-8").strip() for line in iso_file] stopwords = [ss for ss in stopwords if not ss==u''] stopwords = list(set(stopwords)) text = '日本語の自然言語処理は本当にしんどい、と彼は十回言った。' tagger = MeCab.Tagger("-Owakati") tok_text = tagger.parse(text) ws = re.compile(" ") words = [word for word in ws.split(tok_text)] if words[-1] == u"\n": words = words[:-1] ws = [w for w in words if w not in stopwords] print(words) print(ws)
Successfully Completed: It does give out the original tokenized text as well as the one without stopwords
['日本語', 'の', '自然', '言語', '処理', 'は', '本当に', 'しんどい', '、', 'と', '彼', 'は', '十', '回', '言っ', 'た', '。'] ['日本語', '自然', '言語', '処理', '本当に', 'しんどい', '、', '十', '回', '言っ', '。']
There is still 2 issues I am facing though:
a) Is it possible to have 2 stopword lists regarded? namely
iso_file
andsloth_file
? so if the word is either a stopword fromiso_file
orsloth_file
it will be removed? (I tried to use line 14 asstopwords = [line.decode("utf-8").strip() for line in zip('iso_file','sloth_file')]
but received an error as tuple attributes may not be decodedb) The ultimate goal would be to generate a new text file in which all stopwords are removed.
I had created this MWE
### first clean twitter csv import pandas as pd import re import emoji df = pd.read_csv("input.csv") def cleaner(tweet): tweet = re.sub(r"@[^\s]+","",tweet) #Remove @username tweet = re.sub(r"(?:\@|http?\://|https?\://|www)\S+|\\n","", tweet) #Remove http links & \n tweet = " ".join(tweet.split()) tweet = ''.join(c for c in tweet if c not in emoji.UNICODE_EMOJI) #Remove Emojis tweet = tweet.replace("#", "").replace("_", " ") #Remove hashtag sign but keep the text return tweet df['text'] = df['text'].map(lambda x: cleaner(x)) df['text'].to_csv(r'cleaned.txt', header=None, index=None, sep='\t', mode='a') ### remove stopwords import urllib from urllib.request import urlopen import MeCab import re # slothlib slothlib_path = "http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt" sloth_file = urllib.request.urlopen(slothlib_path) #stopwordsiso iso_path = "https://raw.githubusercontent.com/stopwords-iso/stopwords-ja/master/stopwords-ja.txt" iso_file = urllib.request.urlopen(iso_path) stopwords = [line.decode("utf-8").strip() for line in iso_file] stopwords = [ss for ss in stopwords if not ss==u''] stopwords = list(set(stopwords)) with open("cleaned.txt",encoding='utf8') as f: cleanedlist = f.readlines() cleanedlist = list(set(cleanedlist)) tagger = MeCab.Tagger("-Owakati") tok_text = tagger.parse(cleanedlist) ws = re.compile(" ") words = [word for word in ws.split(tok_text)] if words[-1] == u"\n": words = words[:-1] ws = [w for w in words if w not in stopwords] print(words) print(ws)
While it works for the simple input text in the first MWE, for the MWE I just stated I get the error
in method 'Tagger_parse', argument 2 of type 'char const *' Additional information: Wrong number or type of arguments for overloaded function 'Tagger_parse'. Possible C/C++ prototypes are: MeCab::Tagger::parse(MeCab::Lattice *) const MeCab::Tagger::parse(char const *)
for this line:
tok_text = tagger.parse(cleanedlist)
So I assume I will need to make amendments to thecleanedlist
?I have uploaded the cleaned.txt on github for reproducing the issue: [txt on github][1]
Also: How would I be able to get the tokenized list that excludes stopwords back to a text format like cleaned.txt? Would it be possible to for this purpose create a df of ws? Or might there even be a more simple way?
Sorry for the long request, I tried a lot and tried to make it as easy as possible to understand what I'm driving at :-)
Thank you very much! [1]: https://gist.github.com/yin-ori/1756f6236944e458fdbc4a4aa8f85a2c
-
Is it possible to use input variables in keybindings in VS Codium?
In Visual Studio Codium I want to define a command that has a variable parameter.
I want the IDE to open specific file, which name is written in another file. Assume I have the following project structure:
/home/user/myproject/ /home/user/myproject/dir1/ /home/user/myproject/dir1/problem1.py /home/user/myproject/dir1/problem2.py /home/user/myproject/dir2/problem1.py ... /home/user/myproject/pointer.txt
The
pointer.txt
contains path to the file I want to work on. For example, it contains:dir1/problem1
.I have read the documentation here. Now I created the following construction:
keybindings.json
:{ "key": "numpad3", "command": "htmlRelatedLinks.openFile", "args": { "file": "${workspaceFolder}/${input:mycatinput}.py", "method": "vscode.open", "viewColumn": 2, } },
tasks.json
:{ "version": "2.0.0", "tasks": [ { "label": "mycat", "type": "shell", "command": "cat /home/user/myproject/pointer.txt" }, ], "inputs": [ { "id": "mycatinput", "type": "command", "command": "workbench.action.tasks.runTask", "args": "mycat" } ] }
But when I press numpad3, I get an error notification with text:
Unable to open '${input:mycatinput}.py': File not found.
Am I missing something? How do I specify a variable in keybindings.json command, which itself is a result of another command (a shell command, not a vscode command).
-
Can I use multiple different commands for a single file type in coderunner?
"code-runner.executorMap": { "cpp": "cd $dir && g++ -Wall -Wextra -O2 -std=c++14 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" },
Coderunner has a command to run .cpp code, but if I want to use another command, such as adding " < input.txt", I would have to go to settings.json to change it. Is there a way to set up multiple commands on vscode for a single kind of file so I can just simply switch without having to change settings.json?
-
How do I set the default c# file in my Visual Studio Code c# Project?
I am new to using Visual Studio Code. I have always used Visual Studio IDE in Windows. I am trying to run a simple Hello World Program on Mac with VS Code. I ran the following command
dotnet new console
which successfully created the csProj file and Program.cs file with the code
Console.WriteLine("Hello, World!");
Now by issuing dotnet run command I can get the output from this Program as well. But I have a different cs file called "Hello.cs" in the same Project location. How do I get the Hello.cs to run instead of the default "Program.cs" created bydotnet new console
command. I tried giving the following property group in the .csproj file but VS Code reports error this is reserved property.<PropertyGroup><StartupObject>Hello.HelloWorld</StartupObject></PropertyGroup>
Is there another way to choose your default startup CS File if you have multiple CS files in your Project.
-
TIPA package for IPA - velar nasal no longer shows up
I typically use the LaTex/overleaf package 'TIPA' to type IPA characters in overleaf and it has always worked great. But recently, no velar nasals will compile in my document. I use the same command that I always have, \ng, but velar nasals are all absent from the document. Does anyone have an idea for how to fix this? Is there another way to type a velar nasal in overleaf?
-
How to make MathJax faster?
I was working on a website that contains a lot of mathematical expressions. I use MathJax with React (using 'react-mathjax-preview') but I noticed that rendering math equations is slow and can be noticed while refreshing the page. I compared with websites that are using MathJax like Mathematics Stack Exchange and I found that the equations are rendered faster (even with pages that contain a big amount of math expression). So why my math is rendered slower? And how to make it fast like Mathematics Stack Exchange?
Note: I tried to use KaTex with react which was faster than MathJax, But there were some problems with the positioning of fractions and roots and the text style. So I returned to MathJax as it also provides more latex functions and is used more than KaTex.
Note: The problem seems to be worse in cases where math expressions are contained in tables, as they are written in separated
<MathJax />
components.For example, this piece of code is rendered slowly, however it contains only 9 math expressions. (some of the pages I work on contain more than 50 separated math expressions (even while using environments like 'align' environment).
<div> <table className="table-style-a2"> <thead> <tr> <th>Radical in the integral</th> <th>Trigonometric substitution</th> <th>Hyperbolic substitution</th> </tr> </thead> <tbody> <tr> <td><MathJax math={String.raw`$\sqrt{a^2-x^2}$`} /></td> <td><MathJax math={String.raw`$x = a \sin (\theta)$`} /></td> <td><MathJax math={String.raw`$x = a \tanh (\phi)$`} /></td> </tr> <tr> <td><MathJax math={String.raw`$\sqrt{a^2+x^2}$`} /></td> <td><MathJax math={String.raw`$x = a \tan (\theta)$`} /></td> <td><MathJax math={String.raw`$x = a \sinh (\phi)$`} /></td> </tr> <tr> <td><MathJax math={String.raw`$\sqrt{x^2-a^2}$`} /></td> <td><MathJax math={String.raw`$x = a \sec (\theta)$`} /></td> <td><MathJax math={String.raw`$x = a \cosh (\phi)$`} /></td> </tr> </tbody> </table> </div> \\ Just an example
Thanks in advance.
-
Jupyter progress bar empty
I'm running the following line of code from a Huggingface tokenizer on a Jupyter notebook:
my_data.map(tokenize_function, batched=True, num_proc=4, remove_columns=['text'])
I know it has been executed because there are 6 download bars, but there are all empty and show no progress. The numbers are not moving either. I'm wondering if there is an issue, or if I should add
tqdm
although it does not seem like the solution. - Change directory in Jupyter Lab not working
-
What is wrong with my MathJax square bracket syntax?
This mathjax expression (in an asciidoctor document in a VS Code preview using asciidoctor-vscode) fails to render correctly:
stem:[ = x_l = x_( ([m]+1) /2) ]
The ] after the m acts like a ) for the _, and ends it early. How can I force the parser to understand my brackets please?
-
Using Brackets in MathJax - Tree Question
I have used LaTeX using different packages to make trees, e.g. using the format below. Is there a way to get a tree to run using MathJax using the code below? I have a bunch of trees that I coded using the exact format below, and I am wanting to get them online. What would I have to do for the program to recognize the 'forest'? Is there something minor that I could adjust to get it to work?
\begin{forest} for tree={l+=0.5cm} % increase level distance [,roof [1[2[3[4]][4[3]]][3[2[4]][4[2]]][4[2[3]][3[2]]]] [2[1[3[4]][4[3]]][3[1[4]][4[1]]][4[1[3]][3[1]]]] [3[1[2[4]][4[1]]][2[1[4]][4[1]]][4[1[2]][2[1]]]] [4[1[2[3]][3[2]]][2[1[3]][3[1]]][3[1[2]][2[1]]]] ] \end{forest}
-
React Latex/Katex/MathJax
Help me to understand. How can I use latex in react in this way
\documentclass{article} \usepackage{xlop} \begin{document} \opdiv{6000}{34} \opdiv[maxdivstep=3]{6000}{34} \end{document}
Maybe some extension for MathJax (I found longdiv.js and I can't connect it to MathJax config in react "use this package https://www.npmjs.com/package/better-react-mathjax" ) I can only render standart strings ($\frac{}{} \sqrt \cdot and etc..... $) and I don't understand how to use calculations and is it possible?