BetterDocs
Home
Docs

Creation | pd.read_feather()

Method:

pd.read_feather(path, columns=None, use_threads=True, storage_options=None, dtype_backend=<no_default>)

Reads a Feather file into a DataFrame.

Returns:

pandas.core.frame.DataFrame

Parameters:

path: (str or path)-

File path or file-like object containing Feather data.

import pandas as pd

# Write a DataFrame to a Feather file
df = pd.DataFrame({'col1': [1, 2, 3], 'col2': ['A', 'B', 'C']})
df.to_feather('data.feather')

# Read the Feather file
df_loaded = pd.read_feather(path='data.feather')
print(df_loaded)
'''
Output:
   col1 col2
0     1    A
1     2    B
2     3    C
'''

columns: None, Optional-

It is used to specify the group name in the HDF5 file from which the data should be read.

import pandas as pd

# Write a DataFrame to a Feather file
df = pd.DataFrame({'col1': [1, 2, 3], 'col2': ['A', 'B', 'C']})
df.to_feather('data.feather')

# Read the Feather file
df_loaded = pd.read_feather(path='data.feather', columns=['col1'])
print(df_loaded)
'''
Output:
   col1
0     1    
1     2    
2     3    
'''

use_threads: (True or False), Optional-

It controls whether the function should use multiple threads for parallelized reading of data from a Feather file. This can significantly improve performance when reading large datasets, especially on systems with multiple CPU cores.

import pandas as pd

# Write a DataFrame to Feather
df = pd.DataFrame({'col1': range(100000), 'col2': range(100000)})
df.to_feather('data.feather')

# Read with threading (default)
df1 = pd.read_feather('data.feather', use_threads=True)
print(df1.head())
'''
Output:
   col1  col2
0     0     0
1     1     1
2     2     2
3     3     3
4     4     4
'''

storage_options: dict, Optional-

Dictionary of storage-specific options, such as credentials for cloud storage.

dtype_backend: None, Optional-

The dtype_backend parameter is new in Pandas 2.0 which is used to specify the backend for handling the types of data when reading a file.


Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy