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

6 Python file Methods Real Usage

Files always have data in them. For different purposes, you need methods to deal with them. These six file methods of use in this case.

Related: 5 top file modes in python.

Python file methods

Python file methods

Below are the top six file methods in python:
  1. Tell()
  2. Seek()
  3. Flush()
  4. Fileno()
  5. truncate()
  6. isatty()

1. tell()

The usage of tell method is it returns the cursor-position of the file-pointer from the beginning of the file. It tells the current cursor position. The position starts from zero, which is same as of an index.



2. seek()

The usage of seek method is cursor position, from one position to the specified position from the beginning of the file, it moves. Here, the cursor will be sought to a particular location.



3. flush()

The usage of flush method is clean out the internal buffer. Before writing the text in the file, it is best practice to clear out that the internal buffer can be cleared.



4. fileno()

The usage of  fileno method is file-number i.e. a file descriptor as an integer value it returns. If an operating system does not use a file descriptor of the file then an error may occur.



5. truncate()

The usage of truncate method is on the given number of bytes it resizes the file. The current position will be used if the size is not specified.



6. isatty()

The usage of isatty method is Boolean. True if the file is connected to an end device like (tty) device else will return False.





Popular posts from this blog

Explained Ideal Structure of Python Class

How to Check Kafka Available Brokers