我在这里看到:如何在DataFrame中将时间戳转换为日期格式?转换datetype中的时间戳的方法,但至少对我来说,它不起作用.
这是我尝试过的
# Create dataframe
df_test = spark.createDataFrame([('20170809',), ('20171007',)], ['date',])
# Convert to timestamp
df_test2 = df_test.withColumn('timestamp',func.when((df_test.date.isNull() | (df_test.date == '')) , '0')\
.otherwise(func.unix_timestamp(df_test.date,'yyyyMMdd')))\
# Convert timestamp to date again
df_test2.withColumn('date_again', df_test2['timestamp'].cast(stypes.DateType())).show()
Run Code Online (Sandbox Code Playgroud)
但是这会在date_again列中返回null:
+--------+----------+----------+
| date| timestamp|date_again|
+--------+----------+----------+
|20170809|1502229600| null|
|20171007|1507327200| null|
+--------+----------+----------+
Run Code Online (Sandbox Code Playgroud)
什么失败了?
我需要从excel文档创建通知,我正在使用Java和Apache POI.这是我的代码:
//Get path with JFileChooser
public static String LeeRuta(){
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showDialog(chooser, "Seleccionar");
File f =chooser.getSelectedFile();
File camino = f.getAbsoluteFile();
String ruta = camino.getAbsolutePath();
return ruta;
}
//main
public static void main(String args[]) {
String ruta=LeeRuta();
/* Don't know if neccesary, but it didn't works with or without it
InputStream inp;
try {
inp = new FileInputStream(ruta);
} catch (FileNotFoundException ex) {
Logger.getLogger(PruebaExcel.class.getName()).log(Level.SEVERE, null, ex);
}
*/
Workbook exceldoc = null;
// Opening file
try …Run Code Online (Sandbox Code Playgroud) 我正在从复数中清除一个txt,并用fscanf逐字逐句读取txt.问题是当我用fwrite编写干净的txt时,它会将所有内容写在一起.
我试图定义一个字符并仅指定一个空格,但在写入时也添加了"òwD".任何人都知道如何只添加''?
char espa[0];
espa[0]=' ';
f2 = fopen("clean.txt", "w");
while(!feof(f))
{
char reader[100];
int aux;
fscanf (f, "%s", reader);
if feof(f){
printf("%s ", reader);
printf("\n\nFin del fichero\n");
}
else
if(cadena[(strlen(reader)-1)]=='s'){
for(aux=0;aux<(strlen(reader)-1);aux++){
printf("%c", reader[aux]);
}
fwrite(cadena, (strlen(reader))-1, 1, f2); //Add clean word
}
else{
printf(" %s ", reader);
fwrite(reader, (strlen(reader)), 1, f2); //Add normal word
}
fwrite(espa, (strlen(espa)), 1, f2); //Here I try to add the space
}
fclose(f);
fclose(f2);
}
Run Code Online (Sandbox Code Playgroud)