Format text in QTextBrowser in PyQT - formatting

I want to write a text in QTextBrowser in PyQt. I have something like this:
for line in working_data:
word = line.split(";")
self.ui.textBrowser.append("{:30}{:>30}".format(word[1], word[2]))
With this I get something like (left and right alignment):
ID Value
123 10,00
1234 20,00
1 330,00
12345 1,00
I would like to have it like this:
ID Value
123 10,00
1234 20,00
1 330,00
12345 1,00
How to achieve that? I looked here and tried {:30}'.format('test') and {:>30}'.format('test') for right align case, but it would'n reserve 30 places for a first word.

Related

How to foreach sql result

i have the following problem. I have a table like that:
RollID
ItemCode
Quantity
DocNum
CountRollIDs
1234
abcde
5
111
5
at the moment we get 1 line like that above, but we want to have the line repeated CountRollIDs times. So in this case 5 times and want to add a new RollID every time, like 1235 in the second row 1236 in the third row and so on. Is there any way to do that with normal sql?

Pandas Display Format on a specific column

So I want to display a single column with a currency format. Basically with a dollar sign, thousand comma separators, and two decimal places.
Input:
Invoice Name Amount Tax
0001 Best Buy 1324 .08
0002 Target 1238593.1 .12
0003 Walmart 10.32 .55
Output:
Invoice Name Amount Tax
0001 Best Buy $1,324.00 .08
0002 Target $1,238,593.10 .12
0003 Walmart $10.32 .55
Note: I still want to be able to do calculations on it, so it would only be a display feature.
If you are just format to print out, you can try:
df.apply(lambda x: [f'${y:,}'for y in x] if x.name=='Amount' else x)
which creates a new dataframe that looks like:
Invoice Name Amount Tax
0 1 Best Buy $1,324.0 0.08
1 2 Target $1,238,593.1 0.12
2 3 Walmart $10.32 0.55
You can simply add this line (before printing your data frame of course):
pd.options.display.float_format = '${:,.2f}'.format
it will print your columns in the data frame (but only float columns ) like this :
$12,500.00

Data.frame after transpose and data.frame still gives variables as non-numeric

I find myself struggling with data import for further nMDS and Bioenv analysis with "vegan" and "ggplot2". I have a data frame "Taxa" that looks like this (the values are there to mean it is "numeric". —
head(Taxa)
X1 Station1 Stations1_2 Stations1_3 ...
Species1 123 456 789
Species2 123 456 789
Species3 123 456 789
...
After I transpose my data to have the stations (observations) as rows
Taxa <- t(Taxa)
X_1 Species1 Species2 Species3 ...
Station1 123 456 789
Species1_2 123 456 789
Species1_3 123 456 789
...
Now if I check how the data has been transposed I see that it has been converted into a "matrix"
class(Taxa)
[1] "matrix"
Now I can change again the matrix into a data frame
Taxa.df <- data.frame(Taxa)
And what I get then is the following:
head(Taxa.df)
X1 X2 X3
X_1 Species1 Species2 Species3 ...
Station1 123 456 789
Species1_2 123 456 789
Species1_3 123 456 789
...
Now what I would need is to get the first row to become the columns header so that I can restore the initial structure
colnames(Taxa.df)=Taxa.df[1,]
When I do this this happens to the data frame
23 10 16 ....
X_1 Species1 Species2 Species3 ...
Station1 123 456 789
Species1_2 123 456 789
Species1_3 123 456 789
...
I don't manage to get to have the first row as header.
If I can't do this I can't run the transformation I need and all the stats analysis I still need to run. I spent the whole day simply trying to import the data from xlsx on Rstudio for Mac and solve this issue. I hope you guys can help. I did already look around a lot and mostly thought to have found these two links as useful answers, but nothing solved my exact problem.
http://r.789695.n4.nabble.com/Transposing-Data-Frame-does-not-return-numeric-entries-td852889.html
Why does the transpose function change numeric to character in R?
The first variable in your data frame was X1 with values Species1 etc. You should have read your data so that the first variable is numeric (Species1) which you can achieve with argument row.names=1 in the read.* command. Alternatively, you can only transpose the numeric data and then label the rows and columns with the original data. The following may work
mat <- t(Taxa[,-1]) # remove col 1
colnames(mat) <- rownames(Taxa)
mat <- as.data.frame(mat)
However, I think you have not posted the actual output of your R commands, but written by hand the things you think are essential to the structure. So it may be that your data are different than you display, and you may also have non-numeric rows. Just check sum(Taxa) which is number if your data are numeric, and sum(Taxa[,-1]) which is a number if removing the first column is sufficient, and summary(Taxa) which gives Mean and Median for columns which are all numeric (including first row).

VB.net | Save data from DataGridView to text file (Line per line)

The application I designed so far has a DataGridView which loads data from a text file line per line.
All I want is for the code to save the (first row, first column) on the first line as a string, then (first row, second column) on the second line, etc.
Here is an example of what my table looks like:
|-------------------------------------------------------|
| ID | Date | Height | Weight | BMI | Units |
|-------------------------------------------------------|
| 01 | 16/06 | 1.74 | 64 | 20.9 | Metric |
| 02 | 17/06 | 1.74 | 63 | 20.6 | Metric |
|-------------------------------------------------------|
So from this example, after the data has been saved to the text file it should look exactly like this:
01
16/06
1.74
64
20.9
Metric
02
17/06
1.74
63
20.6
Metric
I came across some excellent code which does this with tabs, instead of a next line, here it is:
dgvMeasures.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
dgvMeasures.SelectAll()
IO.File.WriteAllText(fileName, dgvMeasures.GetClipboardContent.GetText.TrimEnd)
dgvMeasures.ClearSelection()
NOTE: The DataGridView is called dgvMeasures
Also please note that I cannot provide anything that I have already tried since there is nothing I can do, I have no idea what to do.
So if there is anyone who could help, it would be greatly appreciated
To do this, you just need to use a writer, and go through it in the way you want.
Using writer As New System.IO.StreamWriter(filePath)
For row As Integer = 0 To dgvMeasures.RowCount - 1
For col As Integer = 0 To dgvMeasures.ColumnCount - 1
writer.WriteLine(dgvMeasures.Rows(row).Cells(col).Value.ToString)
Next
Next
End Using
This will go through each column for each row (as you describe), and then go to the next row.
I am sure you have a reason for writing the text file like this, but if you want to read it back in at some point, I would really recommend using a tab-delimited (or similar) format.

SQL - Exclude four-digit-number

I have an SQL-Server with and simple table on it.
ID | Code
---+--------
1 | 1234
2 | TEST
3 | 12556
4 | TEST1
5 | 5678
6 | WART
I want to exclude all four-digit-number. In my case that would be 1234 and 5678.
I know I can use ISNUMERIC() tp check if code is numeric.
I also know I can use:
SELECT * FROM Codes WHERE code NOT LIKE '____';
to check if my value has four digits, but i dont get it how to combine them.
Any suggentions?
Thanks in advance!
Just use not like:
where code not like '[0-9][0-9][0-9][0-9]'