Showing posts with the label File Formats

Featured Post

How to Check Column Nulls and Replace: Pandas

Here is a post that shows how to count Nulls and replace them with the value you want in the Pandas Dataframe. We have explained the process in two steps - Counting and Replacing the Null values. Count null values (column-wise) in Pandas ## count null values column-wise null_counts = df.isnull(). sum() print(null_counts) ``` Output: ``` Column1    1 Column2    1 Column3    5 dtype: int64 ``` In the above code, we first create a sample Pandas DataFrame `df` with some null values. Then, we use the `isnull()` function to create a DataFrame of the same shape as `df`, where each element is a boolean value indicating whether that element is null or not. Finally, we use the `sum()` function to count the number of null values in each column of the resulting DataFrame. The output shows the count of null values column-wise. to count null values column-wise: ``` df.isnull().sum() ``` ##Code snippet to count null values row-wise: ``` df.isnull().sum(axis=1) ``` In the above code, `df` is the Panda

How to Effectively Parse and Read Different Files in Python

Here is Python logic that shows Parse and Read Different Files in Python. The formats are XML, JSON, CSV, Excel, Text, PDF, Zip files, Images, SQLlite, and Yaml. Python Reading Files import pandas as pd import json import xml.etree.ElementTree as ET from PIL import Image import pytesseract import PyPDF2 from zipfile import ZipFile import sqlite3 import yaml Reading Text Files # Read text file (.txt) def read_text_file(file_path):     with open(file_path, 'r') as file:         text =     return text Reading CSV Files # Read CSV file (.csv) def read_csv_file(file_path):     df = pd.read_csv(file_path)     return df Reading JSON Files # Read JSON file (.json) def read_json_file(file_path):     with open(file_path, 'r') as file:         json_data = json.load(file)     return json_data Reading Excel Files # Read Excel file (.xlsx, .xls) def read_excel_file(file_path):     df = pd.read_excel(file_path)     return df Reading PDF files # Read PDF file (.pdf) def rea