python Library
readCSV
Keine Erläuterungen gefunden.
def readCSV(file, selector=False, debug=False): try: # Read the CSV file with the correct separator and decimal format df = pd.read_csv(file, sep=";", decimal=",") # If a selector is provided, filter and rename columns if selector: df = df[list(selector.keys())] # Keep only selected columns df = df.rename(columns=selector) # Rename columns # Convert all numeric columns to float for col in df.select_dtypes(include=['object']).columns: df[col] = df[col].str.replace(",", ".").astype(float) if debug: echo(f"First lines of {file}", 'warn') # Display the first few rows print(df.head()) return df except FileNotFoundError: echo(f" The file '{file}' was not found.") except pd.errors.EmptyDataError: echo(f" The file '{file}' is empty.") except pd.errors.ParserError: echo(f" The file '{file}' could not be parsed. Check the delimiter and formatting.") except ValueError as e: echo(f" {e}") except Exception as e: echo(f"Unexpected error: {e}") return None # Return None if there's an error
Index of Library
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.