N
N
Nurla2021-03-31 18:35:08
Python
Nurla, 2021-03-31 18:35:08

How to make the right random sample without a special function?

I wrote a code for random data sampling and I understand what the error is, but I can't fix it. You need to write code without a third-party function like sample...
60649672ea553714064021.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nurla, 2021-03-31
@Nurla

There is a second code, but you need to somehow convert the arrays into a dataframe for further use, so I don’t know how to do it (I hope it was clear)
def random_nans(data, n):
data_new = [n]
for i in range(n):
data_new. append(data.loc[np.random.randint(338),:].values)
return data_new
pd.DataFrame(random_nans(data, np.random.randint(90)))

D
dmshar, 2021-04-01
@dmshar

How to convert arrays and lists to DataFrame - described in any pandas manual.
Two dimensional list:

import pandas as pd
import numpy as np
list_a = 
columns = ['a','b','c','d','e']
df_a = pd.DataFrame(list_a, columns=columns)

nympy array:
pd.DataFrame(np.random.rand(3, 2), columns=['foo', 'bar'])

Further a combination of these possibilities.
PS And I draw your attention to the fact that according to the rules of this forum - to put the second question as an answer to the first - is prohibited. And in general, the rule is "one topic - one question", i.e. a new question is framed by a new topic. Maybe you, as a beginner, will be forgiven, but in general, they can get banned for this.
And yet - no one wants to break their eyes with a picture. All codes should be given in the text of the question in the form of a minimally reproduced fragment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question