我如何以4:1的比例随机分割数据帧(csv)并将其存储在两个不同的变量中 ex-如果数据帧中有10行从1到10,我希望变量'a'中有10行,而变量'b'中其余2行。
答案 0 :(得分:0)
我从来没有随机做过,但是基本方法是:
代码示例:
# importing pandas module
import pandas as pd
# read in csv file
data = pd.read_csv("https://mydata.csv")
# drop null values
data.dropna(inplace = True)
# create new data frame
new = data["ColumnName"].str.split(" ", n = 1, expand = True) #this 'split' code applies to splitting one column into two
# assign new name to first column
data["A"]= new[0] #8 concatenated values will go here
# making seperate last name column from new data frame
data["B"]= new[1] #last two [combined] values in go here
## other/different code required for concatenation of column values-查看此链接的SO问题##
# df display
data
希望这会有所帮助