Icon

kn_​forum_​67850_​csv_​kaggle_​data_​import

Import a CSV file from Kaggle and do some manipulations with date format and duration

Import a CSV file from Kaggle and do some manipulations with date format and duration
https://forum.knime.com/t/knime-data-import-problem/67850?u=mlauber71

Import a CSV file from Kaggle and do some manipulations with date format and durationhttps://forum.knime.com/t/knime-data-import-problem/67850/3?u=mlauber71 // Code in "method body" boxString duration = c_Duration; // replace "Duration" with your actual column nameString[] parts = duration.split(":");int hours = 0;int minutes = 0;int seconds = 0;if (parts.length == 3) { hours = Integer.parseInt(parts[0]); minutes = Integer.parseInt(parts[1]); seconds = Integer.parseInt(parts[2]);} else if (parts.length == 2) { minutes = Integer.parseInt(parts[0]); seconds = Integer.parseInt(parts[1]);}out_Hours = hours; // "out_Hours" is a new Integer column for hoursout_Minutes = minutes; // "out_Minutes" is a new Integer column for minutesout_Seconds = seconds; // "out_Seconds" is a new Integer column for seconds// Construct an ISO 8601 duration stringout_duration_txt = String.format("PT%dH%dM%dS", hours, minutes, seconds); Mr Beast Most Watched Videos.csvwatched_videos.tableMMM d, yyyyduration_txtextract durationCSV Reader Table Writer String to Date&Time String to Duration Java Snippet clear theDate column Import a CSV file from Kaggle and do some manipulations with date format and durationhttps://forum.knime.com/t/knime-data-import-problem/67850/3?u=mlauber71 // Code in "method body" boxString duration = c_Duration; // replace "Duration" with your actual column nameString[] parts = duration.split(":");int hours = 0;int minutes = 0;int seconds = 0;if (parts.length == 3) { hours = Integer.parseInt(parts[0]); minutes = Integer.parseInt(parts[1]); seconds = Integer.parseInt(parts[2]);} else if (parts.length == 2) { minutes = Integer.parseInt(parts[0]); seconds = Integer.parseInt(parts[1]);}out_Hours = hours; // "out_Hours" is a new Integer column for hoursout_Minutes = minutes; // "out_Minutes" is a new Integer column for minutesout_Seconds = seconds; // "out_Seconds" is a new Integer column for seconds// Construct an ISO 8601 duration stringout_duration_txt = String.format("PT%dH%dM%dS", hours, minutes, seconds); Mr Beast Most Watched Videos.csvwatched_videos.tableMMM d, yyyyduration_txtextract durationCSV Reader Table Writer String to Date&Time String to Duration Java Snippet clear theDate column

Nodes

Extensions

Links