pyspark parse fixed width text file

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.substr(4,8).alias(‘date’), df.value.substr(12,3).alias(‘string’), df.value.substr(15,4).cast(‘integer’).alias(‘integer’) ).show() will result in: +—+——–+——+——-+ | id| date|string|integer| +—+——–+——+——-+ |001|01292017| you| 1234| |002|01302017| me| 5678| +—+——–+——+——-+ Having splitted columns you can reformat and use them as in normal spark dataframe.

Using calc() with tables

Tables have difficult rules about distributing the space of the columns because they distribute space dependent on the content of the cells by default. Calc (atm) just wont work with that. What you can do however is to set the table-layout attribute for the table to force the child td elements to get the exact … Read more

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

See: http://jsfiddle.net/qx32C/36/ .lineContainer { overflow: hidden; /* clear the float */ border: 1px solid #000 } .lineContainer div { height: 20px } .left { width: 100px; float: left; border-right: 1px solid #000 } .right { overflow: hidden; background: #ccc } <div class=”lineContainer”> <div class=”left”>left</div> <div class=”right”>right</div> </div> Why did I replace margin-left: 100px with overflow: … Read more

Fluid or fixed grid system, in responsive design, based on Twitter Bootstrap

When you decide between fixed width and fluid width you need to think in terms of your ENTIRE page. Generally, you want to pick one or the other, but not both. The examples you listed in your question are, in-fact, in the same fixed-width page. In other words, the Scaffolding page is using a fixed-width … Read more

Read fixed width record from text file

Use FileHelpers. Example: [FixedLengthRecord()] public class MyData { [FieldFixedLength(8)] public string someData; [FieldFixedLength(16)] public int SomeNumber; [FieldFixedLength(12)] [FieldTrim(TrimMode.Right)] public string someMoreData; } Then, it’s as simple as this: var engine = new FileHelperEngine<MyData>(); // To Read Use: var res = engine.ReadFile(“FileIn.txt”); // To Write Use: engine.WriteFile(“FileOut.txt”, res);

Read fixed width text file

This is a fixed width file. Use read.fwf() to read it: x <- read.fwf( file=url(“http://www.cpc.ncep.noaa.gov/data/indices/wksst8110.for”), skip=4, widths=c(12, 7, 4, 9, 4, 9, 4, 9, 4)) head(x) V1 V2 V3 V4 V5 V6 V7 V8 V9 1 03JAN1990 23.4 -0.4 25.1 -0.3 26.6 0.0 28.6 0.3 2 10JAN1990 23.4 -0.8 25.2 -0.3 26.6 0.1 28.6 0.3 … Read more