I have some data which I run through, which generates a textfile.
The data is all pulled correctly, but it doesn't format correctly.
Right now, I am using TAB + Variable to space between each column but it is obviously made uneven as different variables differ in character length. Here is the layout:
RECORD NAME ADDRESS TELEPHONE SOMETHING SOMETHING
... Data is here.
Any ideas?
String.Format is your friend here.
It's very powerfull and gives you the function to align your output.
For example:
(EDIT: removed the txt prefix because could be confusing, now I suppose that data to be formatted is contained in string vars)
Dim result as string
result = String.Format("{0,-10}{1,-30}{2,-30}{3,-10}{4,20}", Record, Name, Address, Telephone, Something)
The result will be aligned to the left in a 10 space column for the first element (txtRecord) and so on for the remainders, the last element will be formatted in a column with 20 space and right aligned
If that's not enough look at composite formatting to get other useful options
Related
So I have a column called censusbloccode2. I have just read this in from a fixed width file. The desired task is to have it to the following
If censusbloccode2 is blank then input a "0". If it has anything in it.. then leave it alone
When I broke up the fixed width text file... it is designated as a char (1) if that helps.
All of the search results that I have seen query this using a select.
I have a numeric text file whose data need to be tabulated. Unfortunately, depending on the input data, this text file shows numbers which are not separed, one to each other, from a fixed number of spaces and unfortunately this number of space could not be the same from a row to another.
I tried this:
For Each line In RichTextBox2.Lines
If Not line.Trim.ToString = "" Then
Dim item() As String = line.Trim.Split(" "c)
DataGridView1.Rows.Add(item)
End If
Next
and then I used to erase the blank columns. But I realised that when the number of space is different on the rows, I have data, that should fill the same column, that are on two or three different columns (with spaces). Let me provide an example:
Here there are the numbers coming from the text file and here are the tabulated numbers.
What I would do, is to erase all the spaces except one, in order to have these numbers equally spaced one from another. Hoping to have been clear, I thank you so much for the support
In the df structure below
enter image description here
I want to write the contents of row 0 as the column name. What should I do?
The actual number of columns is very large (more than 50)
enter image description here
This might help
header = df.iloc[0]
new_df = pd.DataFrame(df.values[1:], columns=header)
It looks like the input file you read your DataFrame from contained column names
in its first row.
You probably read your DataFrame calling either read_csv or read_fwf.
Both these functions have header parameter, which you probably set to
None and in this case:
column names are created as consecutive numbers, starting from 0,
the first row of input file is read as a regular data row.
If I am right, change the way you read your DataFrame.
Maybe it is be enough to remove header parameter (its default value
of infer is sufficient).
I am having trouble changing the title of some columns in a pivot table. I'm trying to make them have dates in them. Each date 6 days further from the last.
Like this
But, I cannot get an equation inside the column title to stay, every time I type in the equation and press enter, it evaluates to either 0 (If the format of the cell is number or general), or 1/0/1990 (If formatted as a date). I checked the value of the cell by =ISTEXT(A1) and it evaluates as true. No matter how I format the cell. So I can never change the title to look like the picture. Any ides?
Here is what I have.
TRUE is the result from ISTEXT()
Even if I manually enter in the formula via the function arguments, it'll show up correct, but when I click ok. It will go back to either 0 or 1/0/1990
Here's the original page
https://drive.google.com/file/d/0B3p8Jm7oNAo4ZUN0Qk1mR1cxYmM/view?usp=sharing
In Excel, dynamic values (formulas) in the header of a table-formatted table are not allowed.
Instead, you can first generate your table header and then format the table as (pivot-)table. You should get a message saying that the header row will be converted in static text (with correct format).
I want to create a makro in Excel which performs - after pressing a button - the below. I attached some dummy data that is formatted like the actual sheet.
There are several data blocks that are seperated by headlines in Sheet 1. From these headlines, I want to get a string of numbers and put it into column S for each line with data below that heading. In line 6 the heading says "2000", thus lines 8-19 should have a "2000" in column S and so on. The number I want to get is always after the word "Monthlyaccount" but the lenght of the number can be different - from 1 to 7 digits.
For lines where no data is given (data lines might be recognized by looking if in A is a valid date given) there should just be "ERR" instead of the number.
Can anyone help out?
Thanks so much upfront!
Say the string (in cell A1) contains "Monthlyaccount" followed by a blank followed by a number followed by another blank. To extract the number, use:
=--LEFT(MID(A1,FIND("Monthlyaccount",A1)+15,9999),-1+FIND(" ",MID(A1,FIND("Monthlyaccount",A1)+15,9999)))
This does as requested. Paste the following into S3 and drag down
=IF(AND(ISNUMBER(RIGHT(A2,4)*1),ISNUMBER(RIGHT(A3,4)*1)),S2,IF(ISNUMBER(RIGHT(A3,4)*1),LEFT(RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14),FIND(" ",RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14))),"ERR"))