“Pandas Shuffle Rows” Kode Jawaban

Python secara acak menyiram deretan data panda

# Basic syntax:
df = df.sample(frac=1, random_state=1).reset_index(drop=True)
# Where:
#	- frac=1 specifies returning 100% of the original rows of the 
#		dataframe (in random order). Change to a decimal (e.g. 0.5) if
#		you want to sample say, 50% of the original rows
#	- random_state=1 sets the seed for the random number generator and
#		is useful to specify if you want results to be reproducible
#	- .reset_index(drop=True) specifies resetting the row index of the
#		shuffled dataframe
Charles-Alexandre Roy

Pandas Shuffle Rows

df = df.sample(frac=1).reset_index(drop=True)
Cook's Tree Boa

Baris Shuffle DataFrame

df = df.sample(frac=1).reset_index(drop=True) #Use if you want to reset index order

df.sample(frac=1) # Use for no reset in index order
Careful Coyote

kocok data panda secara acak

  shuffled_train_df = train_df.reindex(np.random.permutation(train_df.index))
Important Iguana

Jawaban yang mirip dengan “Pandas Shuffle Rows”

Pertanyaan yang mirip dengan “Pandas Shuffle Rows”

Lebih banyak jawaban terkait untuk “Pandas Shuffle Rows” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya