fixed-width

Fixed width to CSV

痞子三分冷 提交于 2019-11-28 11:48:27
I know how to use awk to change fixed width to CSV. What I have is a hard drive with a few thousand fixed width files. The all contain different column width formats, but it is "encoded" on the second line as: Name DOB GENDER ============== ======== ====== JOHN DOE 19870130 M MARY DOE 19850521 F MARTY MCFLY 19790320 M I want to convert ALL the files to CSV. I can write a program that reads in the first line and holds it for column names. Then, it loads the second line to get the column widths. Then, it uses awk to convert that file to CSV. What I'd prefer to do is find a program that

Is it possible to fix axis margin with ggplot2?

无人久伴 提交于 2019-11-28 11:27:19
I have an interactive display consisting of a bar chart that shows a selected statistic for different categories. However, ggplot2 readjusts the y-axis width depending on the labels, and hence makes the bars annoyingly move on the x-direction. See exemple: library(shiny) library(dplyr) library(ggplot2) shinyApp( ui = bootstrapPage( selectInput('statistic', label='Chose a statistic', choices=c('carat', 'depth', 'table', 'price')), plotOutput('plot') ), server = function(input, output) { output$plot <- renderPlot( diamonds %>% ggplot(aes(x=color, y=get(input$statistic))) + geom_bar(stat = 'sum')

Python Pandas, write DataFrame to fixed-width file (to_fwf?)

夙愿已清 提交于 2019-11-28 09:58:34
I see that Pandas has read_fwf , but does it have something like DataFrame.to_fwf ? I'm looking for support for field width, numerical precision, and string justification. It seems that DataFrame.to_csv doesn't do this. numpy.savetxt does, but I wouldn't want to do: numpy.savetxt('myfile.txt', mydataframe.to_records(), fmt='some format') That just seems wrong. Your ideas are much appreciated. Until someone implements this in pandas, you can use the tabulate package: import pandas as pd from tabulate import tabulate def to_fwf(df, fname): content = tabulate(df.values.tolist(), list(df.columns),

XML to Fixed width text file with xsl style sheet

大城市里の小女人 提交于 2019-11-27 22:28:16
问题 I need help formatting this xml to a fixed width text file using a xsl style sheet. I know very little about xsl and have found very little information online on how this can be done. Basically I need this xml <?xml version="1.0" encoding="UTF-8"?> <Report> <table1> <Detail_Collection> <Detail> <SSN>*********</SSN> <DOB>1980/11/11</DOB> <LastName>user</LastName> <FirstName>test</FirstName> <Date>2013/02/26</Date> <Time>14233325</Time> <CurrentStreetAddress1>53 MAIN STREET<

pyspark parse fixed width text file

喜欢而已 提交于 2019-11-27 08:01:15
问题 Trying to parse a fixed width text file. my text file looks like the following and I need a row id, date, a string, and an integer: 00101292017you1234 00201302017 me5678 I can read the text file to an RDD using sc.textFile(path). I can createDataFrame with a parsed RDD and a schema. It's the parsing in between those two steps. 回答1: Spark's substr function can handle fixed-width columns, for example: df = spark.read.text("/tmp/sample.txt") df.select( df.value.substr(1,3).alias('id'), df.value

Is it possible to fix axis margin with ggplot2?

こ雲淡風輕ζ 提交于 2019-11-27 06:20:30
问题 I have an interactive display consisting of a bar chart that shows a selected statistic for different categories. However, ggplot2 readjusts the y-axis width depending on the labels, and hence makes the bars annoyingly move on the x-direction. See exemple: library(shiny) library(dplyr) library(ggplot2) shinyApp( ui = bootstrapPage( selectInput('statistic', label='Chose a statistic', choices=c('carat', 'depth', 'table', 'price')), plotOutput('plot') ), server = function(input, output) { output

What's the best way of parsing a fixed-width formatted file in Java?

隐身守侯 提交于 2019-11-27 01:36:56
I've got a file from a vendor that has 115 fixed-width fields per line. What's the best way of parsing that file into the 115 fields so I can use them in my code? My first thought is just to make constants for each field like NAME_START_POSITION and NAME_LENGTH and using substring . That just seems ugly so I'm curious if there's any other recommended ways of doing this. None of the couple of libraries a Google search turned up seemed any better either. Thanks Pascal Thivent I would use a flat file parser like flatworm instead of reinventing the wheel: it has a clean API, is simple to use, has

How to make an inline-block element fill the remainder of the line?

社会主义新天地 提交于 2019-11-26 21:20:54
Is such a thing possible using CSS and two inline-block (or whatever) DIV tags instead of using a table? The table version is this (borders added so you can see it): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body> <table style="width:100%;"> <tr> <td style="border:1px solid black;width:100px;height:10px;"></td> <td style="border:1px solid black;height:10px;"></td> </tr> </table> </body> </html> It produces a left column with a FIXED WIDTH (not a percentage

Using calc() with tables

我的未来我决定 提交于 2019-11-26 16:47:18
I'm trying to get a table with fixed-width td s and variable-width td s. Im using the CSS calc() function, but somehow it seems like I can't use % in tables. So that is what I have so far: <table border="0" style="width:100%;border-collapse:collapse;"> <tr style="width:100%"> <td style="width:30px;">1</td> <!--Fixed width--> <td style="width: calc( (100% - 230px) / 100 * 40);">Title</td> <!--Width should be 40% of the remaining space--> <td style="width: calc( (100% - 230px) / 100 * 40);">Interpret</td> <!--Width should be 40% of the remaining space--> <td style="width: calc( (100% - 230px) /

Read fixed width record from text file

余生长醉 提交于 2019-11-26 16:35:58
I've got a text file full of records where each field in each record is a fixed width. My first approach would be to parse each record simply using string.Substring(). Is there a better way? For example, the format could be described as: <Field1(8)><Field2(16)><Field3(12)> And an example file with two records could look like: SomeData0000000000123456SomeMoreData Data2 0000000000555555MoreData I just want to make sure I'm not overlooking a more elegant way than Substring(). Update: I ultimately went with a regex like Killersponge suggested: private readonly Regex reLot = new Regex(REGEX_LOT,