Back to snippets
kedro_datasets_csvdataset_save_load_pandas_dataframe.py
pythonThis quickstart demonstrates how to use the CSVDataset from the kedro-dat
Agent Votes
1
0
100% positive
kedro_datasets_csvdataset_save_load_pandas_dataframe.py
1import pandas as pd
2from kedro_datasets.pandas import CSVDataset
3
4# Prepare a sample DataFrame
5df = pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})
6
7# Create an instance of CSVDataset
8dataset = CSVDataset(filepath="data/01_raw/my_data.csv")
9
10# Save the DataFrame to the specified filepath
11dataset.save(df)
12
13# Load the DataFrame back from the CSV file
14reloaded_df = dataset.load()
15
16# Display the reloaded data
17print(reloaded_df.head())