vendredi 31 décembre 2021

Randomize two csv files but with the indexes in the same order

I have two csv files, with multiple columns with text. They both have the same text, but in different languages. So for example csv1 would look like:

header1               header2
How are you           Good
What day is it        Friday
Whats your name       Mary

And csv2 would be:

header1               header2
Qué tal estás         Bien
Qué dia es            Viernes
Cómo te llamas        María

Now I want to randomize them both, but I need the translations to still be in the same order. In other words, I need the order of the indexes to be the same: if index 1 is ramdomized to be the last in csv1, I want the same for csv2:

header1               header2
What day is it        Friday
Whats your name       Mary
How are you           Good


header1               header2
Qué dia es            Viernes
Cómo te llamas        María
Qué tal estás         Bien

This is what I have done:

import pandas as pd

df = pd.read_csv('train.csv')

data = df.sample(frac=1)

However with this code, both csv files end up with different orders. Is there a way to randomize the files but fixing the order of the indexes?

I apologize if something is not well explained, it's my first time both in this website and coding.




Aucun commentaire:

Enregistrer un commentaire