फॉर्मेटेड CSV फाइलें लिखना
डेटा क्लीन करने के बाद, आपको उसे अलग‑अलग उपभोक्ताओं के लिए एक्सपोर्ट करना है. एनालिटिक्स टीम को स्टैंडर्ड CSV चाहिए, यूरोपीय सिस्टम सेमीकोलन सेपरेटर अपेक्षित करते हैं, और एक लेगेसी मेनफ्रेम को हेडर‑लेस फाइलें चाहिए. लचीले एक्सपोर्ट विकल्प यह सुनिश्चित करते हैं कि आपका डेटा विभिन्न तकनीकी माहौल में आसानी से इंटीग्रेट हो सके.
Table और CsvWriteOptions क्लास आपके लिए इम्पोर्ट कर दी गई हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Java में डेटा इम्पोर्ट करना
अभ्यास निर्देश
- टेबल को स्टैंडर्ड CSV के रूप में लिखें.
- सेमीकोलन सेपरेटर के साथ लिखें.
- लेगेसी सिस्टम के लिए हेडर के बिना लिखें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
public class WriteCSVFiles {
public static void main(String[] args) {
try {
Table employeePerformance = Table.read().csv("employee_performance.csv");
System.out.println("Original data structure:");
System.out.println(employeePerformance.structure());
System.out.println("First 3 rows:");
System.out.println(employeePerformance.first(3));
// Write the table as a standard CSV
employeePerformance.____.csv("employee_performance_standard.csv");
// Write with a semicolon separator
employeePerformance.write().csv(CsvWriteOptions
.____("employee_performance_semicolon.csv")
.____(';')
.build());
// Write without headers for a legacy system
employeePerformance.write().csv(CsvWriteOptions
.builder("employee_performance_noheader.csv")
.____(____)
.build());
System.out.println("\nFiles successfully written to output directory.");
Table readBack = Table.read().csv("employee_performance_standard.csv");
System.out.println("\nVerification - Reading back semicolon-separated file:");
System.out.println(readBack.first(3));
} catch (Exception e) {
System.err.println("Error processing CSV files: " + e.getMessage());
}
}
}