返回顶部

[今日热搜] 使用 sample() 方法可以拆分 DataFrame吗,如何做呢[手机搜狐网]

0

0/300

评论 1

初生

我们可以通过使用 sample() 方法从 DataFrame 中随机抽取行来形成一个 DataFrame。我们可以设置从父 DataFrame 中抽取行的比例。 import pandas as pd apprix_df = pd.DataFrame({ 'Name': ["Anish","Rabindra","Manish","Samir","Binam"], 'Post': ["CEO","CTO","System Admin","Consultant","Engineer"], 'Qualification':["MBA","MS","MS","PhD","MS"] }) print("Apprix Team DataFrame:") print(apprix_df,"\n") random_df = apprix_df.sample(frac=0.4,random_state=60) print("Random split from the Apprix Team DataFrame:") print(random_df) 输出: Apprix Team DataFrame: Name Post Qualification 0 Anish CEO MBA 1 Rabindra CTO MS 2 Manish System Admin MS 3 Samir Consultant PhD 4 Binam Engineer MS Random split from the Apprix Team DataFra

2021-11-23 15:01:26

- 没有更多了 -