# Are there Flower examples with CSV files?

**URL:** <https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416>\
**Category:** Flower Framework\
**Tags:** csv, example\
**Created:** [November 14, 2024, 1:34pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416 "2024-11-14T13:34:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![charles](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/charles/32/92_2.png) [@charles](https://discuss.flower.ai/u/charles)\
**Post date:** [November 14, 2024, 1:34pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/1 "2024-11-14T13:34:46Z")

</div>

> [@](#):
>
> [**View in #questions on Slack**](https://slack.com/archives/C01RM6LMKQA/p1731407004435099)
> 
> ![Meenakshi_Mittal](https://europe1.discourse-cdn.com/flex013/uploads/flower/original/1X/9254a5ce4ba21eaa5588fbf90ff7c8bbc4bb3b31.png) **@Meenakshi\_Mittal:** Can anyone provide a demo of federated learning on numerical data and data read from CSV files, as the existing demo was on image data?
> 
> ![Charles_Beauville](https://europe1.discourse-cdn.com/flex013/uploads/flower/original/1X/b6d725d54bfa615b9c2ffa7060cd0c40fe5c58e0.png) **@Charles\_Beauville:** Hi @Meenakshi\_Mittal, you can checkout [this Scikit Learn regression example](https://github.com/adap/flower/tree/main/examples/quickstart-sklearn-tabular), or [this Torch classifier example](https://github.com/adap/flower/tree/main/examples/fl-tabular), both are using tabular data. But they use Flower Datasets to facilitate partitioning instead of manual CSV loading. You can checkout [this guide](https://flower.ai/docs/datasets/how-to-use-with-local-data.html) to see how to use a local CSV file with Flower Datasets

---

<div class="post-metadata">

**Author:** ![charles](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/charles/32/92_2.png) [@charles](https://discuss.flower.ai/u/charles)\
**Post date:** [November 14, 2024, 1:36pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/2 "2024-11-14T13:36:23Z")

</div>

Both [this Scikit Learn regression example](https://github.com/adap/flower/tree/main/examples/quickstart-sklearn-tabular), or [this Torch classifier example](https://github.com/adap/flower/tree/main/examples/fl-tabular), are using tabular data. But they use Flower Datasets to facilitate partitioning instead of manual CSV loading. You can checkout [this guide](https://flower.ai/docs/datasets/how-to-use-with-local-data.html) to see how to use a local CSV file with Flower Datasets

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://discuss.flower.ai/u/peter)\
**Post date:** [November 20, 2024, 1:58pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/3 "2024-11-20T13:58:46Z")

</div>

Hello,  
I have modified the code of the first tutorial in the official Flower website.

I got the following:

```auto
def get_dataloaders(partition_id: int):
    
    
    train_data = pd.read_csv( IRIS_DATASET_PATH / 'Train' / 'Train.csv' )
    test_data = pd.read_csv( IRIS_DATASET_PATH / 'Test' / 'Test.csv' )
    df_data = pd.DataFrame( np.concatenate( [train_data.values, test_data.values], axis = 0 ) )
    
    
    partitioner = IidPartitioner( num_partitions = NUM_CLIENTS )
    partitioner.dataset = Dataset.from_pandas( df_data )
    
    
    partition = partitioner.load_partition( partition_id = partition_id )
    
    
    # ******************************************************
    # DIVIDE DATA ON EACH NODE: 80% TRAIN, 20% VALID + TEST
    # ******************************************************
    partition_train_test = partition.train_test_split( test_size = 0.2, 
                                                       seed = 42 )
    
    partition_valid_test = partition_train_test['test'].train_test_split( test_size = 0.5, 
                                                                          seed = 42 )
    
    
    def apply_transforms( batch ):
        # Instead of passing transforms to CIFAR10(..., transform=transform)
        # we will use this function to dataset.with_transform(apply_transforms)
        # The transforms object is exactly the same
        for key in batch.keys():
            
            batch[key] = torch.tensor( batch[key] )
        
        return batch

    partition_train_test = partition_train_test.with_transform( apply_transforms )
    
    partition_valid_test = partition_train_test.with_transform( apply_transforms )
    
    train_dataloader = torch.utils.data.DataLoader( dataset = partition_train_test["train"], 
                                                    batch_size = BATCH_SIZE, 
                                                    shuffle = True )
    
    valid_dataloader =torch.utils.data. DataLoader( dataset = partition_valid_test["train"], 
                                                    batch_size = BATCH_SIZE )
                   
    test_dataloader = torch.utils.data.DataLoader( dataset = partition_valid_test["test"], 
                                                    batch_size = BATCH_SIZE )
    
    return train_dataloader, valid_dataloader, test_dataloader

```

Well, when I run Flower, it freezes.

I have not been understanding what I am doing wrong.

Regards

---

<div class="post-metadata">

**Author:** ![adam-narozniak](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/adam-narozniak/32/33_2.png) [@adam-narozniak](https://discuss.flower.ai/u/adam-narozniak)\
**Post date:** [November 21, 2024, 3:21pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/4 "2024-11-21T15:21:46Z")

</div>

I’d advise to check the change in the centralized setup first.

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://discuss.flower.ai/u/peter)\
**Post date:** [November 21, 2024, 3:25pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/5 "2024-11-21T15:25:10Z")

</div>

Dear @adam-narozniak ,  
many thanks for your feedback, but I only changed the function “load\_datasets” which I renamed “get\_dataloaders”.

Best regards,

---

<div class="post-metadata">

**Author:** ![adam-narozniak](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/adam-narozniak/32/33_2.png) [@adam-narozniak](https://discuss.flower.ai/u/adam-narozniak)\
**Post date:** [November 21, 2024, 3:32pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/6 "2024-11-21T15:32:23Z")

</div>

Well, if it worked before and now it does not work, the problem is likely there. Debugging in an FL setup is hard. So, if you want to get a clearer picture of what’s going on and possibly share the error or problem further, that’d be the way to go. But feel free to try to solve it in the whole FL pipeline if that suits you, but can’t future help without any new information :((

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://discuss.flower.ai/u/peter)\
**Post date:** [November 21, 2024, 3:35pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/7 "2024-11-21T15:35:04Z")

</div>

Dear @adam-narozniak ,

I think you are right. As the first debugging step, I will follow your suggestion and, eventually, I will let you know.

Thanks again!

---

<div class="post-metadata">

**Author:** ![charles](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/charles/32/92_2.png) [@charles](https://discuss.flower.ai/u/charles)\
**Post date:** [November 28, 2024, 3:35pm UTC](https://discuss.flower.ai/t/are-there-flower-examples-with-csv-files/416/8 "2024-11-28T15:35:22Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
