i did try some method like stop when encountered blank rows or duplicated data but i think my code was wrong
this is my .csv data
`25;208A;642335;213;9;89.55;2.03;1.06;7.18;0.19;x
26;208A;645054;215;8;89.64;1.62;1.23;7.32;0.19;x
27;208A;635021;212;4;89.11;2.86;0.69;7.19;0.14;x
28;208A;612817;204;8;88.05;3.49;0.77;7.58;0.12;x
29;208A;638854;212;7;89.47;2.55;0.37;7.47;0.14;x
30;208A;645899;216;3;89.71;2.33;0.33;7.38;0.25;x
All;-;18234161;5691;442;2681.19;58.94;56.98;198.87;4.02;x
[Recipe ID;Recipe Name;Length;Full Packages;Yarn Breaks;!]
202;PDPM5G 602EPH 5000M;115543;23;3;x
202D;PDPM5Q 602EPH 5000M;49652;9;0;x
204;PPPL4G 502EPH 4000Y;514076;141;12;x
208A;PUPM3G 302 EPH 3000M ;9589642;3191;125;x
212;P7PL2G 173EPH 2000Y;2140536;1165;34;x
224;LVLM5G 452PPT 5000M;1418162;281;18;x
224B;LVLM5G 452PPT 5000M;1678530;337;191;x
301Y;FEYM5G 1501ETF 5000M;223831;44;1;x
302A;FAFM5G 1002FST 5000M;2504189;500;58;x
[Recipe ID;Recipe Name;Production (%);Stop (%);Yarn break (%);Doffing (%);Error (%);!]
202;PDPM5G 602EPH 5000M;93.43;0.45;0.38;5.72;0.02;x
202D;PDPM5Q 602EPH 5000M;93.87;0.44;0.55;5.13;0.00;x
204;PPPL4G 502EPH 4000Y;88.33;0.72;3.78;7.09;0.08;x
208A;PUPM3G 302 EPH 3000M ;89.32;2.11;1.04;7.38;0.15;x`
and the data that i wanna take
[Recipe ID;Recipe Name;Length;Full Packages;Yarn Breaks;!] 202;PDPM5G 602EPH 5000M;115543;23;3;x 202D;PDPM5Q 602EPH 5000M;49652;9;0;x 204;PPPL4G 502EPH 4000Y;514076;141;12;x 208A;PUPM3G 302 EPH 3000M ;9589642;3191;125;x 212;P7PL2G 173EPH 2000Y;2140536;1165;34;x 224;LVLM5G 452PPT 5000M;1418162;281;18;x 224B;LVLM5G 452PPT 5000M;1678530;337;191;x 301Y;FEYM5G 1501ETF 5000M;223831;44;1;x 302A;FAFM5G 1002FST 5000M;2504189;500;58;x
this is my demo code about this problem
import pandas as pd
import os
def combine_csv_data(folder_path):
final_df = pd.DataFrame().set_flags(allows_duplicate_labels=False)
for filename in os.listdir(folder_path):
if filename.endswith(".csv"):
try:
file_path = os.path.join(folder_path, filename)
# Read CSV with appropriate delimiter (replace ";" with your actual delimiter)
df = pd.read_csv(file_path, delimiter=";", skiprows=44)
final_df = df[["[Recipe ID", "Full Packages"]]
#final_df = pd.concat([final_df, df], ignore_index=True)
except FileNotFoundError:
print(f"Error: File not found - {filename}")
except pd.errors.ParserError as e:
print(f"Error parsing file: {filename}. Reason: {e}")
continue # Move on to the next file
return final_df
if __name__ == "__main__":
folder_path = "E:/Python" # Replace with your actual folder path
final_df = combine_csv_data(folder_path)
print(final_df.head()) # View the first few rows of the combined DataFrame
print(final_df.shape) # Print the DataFrame dimensions (number of rows, columns)
# To save the combined DataFrame to a new CSV file:
final_df.to_csv("combined_data.csv", index=False)
Hope you guys help me fix this problem tysm
Phong Hoài is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.