Commit 955baddc3e
Unsigned
Layout: unified · split
sampling/sample.py +7 −3
| @@ -1,8 +1,12 @@ | |||
| 1 | """ | ||
| 2 | Creates a sample from a CSV or Excel file based on user-defined SAMPLE_SIZE. | ||
| 3 | """ | ||
| 4 | |||
| 1 | # Import packages | 5 | # Import packages |
| 2 | import pandas as pd | 6 | import pandas as pd |
| 3 | 7 | ||
| 4 | # Define the sample size | 8 | # Define the sample size |
| 5 | sample_size = 25 | 9 | SAMPLE_SIZE = 25 |
| 6 | 10 | ||
| 7 | # Import the data to a pandas DataFrame | 11 | # Import the data to a pandas DataFrame |
| 8 | df = pd.read_csv("FILENAME_GOES_HERE.csv") | 12 | df = pd.read_csv("FILENAME_GOES_HERE.csv") |
| @@ -15,8 +19,8 @@ df = pd.read_csv("FILENAME_GOES_HERE.csv") | |||
| 15 | print("Dataframe size (rows, columns): ", df.shape) | 19 | print("Dataframe size (rows, columns): ", df.shape) |
| 16 | 20 | ||
| 17 | # Sample | 21 | # Sample |
| 18 | sample = df.sample(sample_size) | 22 | sample = df.sample(SAMPLE_SIZE) |
| 19 | print("Sample size: ", sample_size) | 23 | print("Sample size: ", SAMPLE_SIZE) |
| 20 | print("Sample:\n", sample) | 24 | print("Sample:\n", sample) |
| 21 | 25 | ||
| 22 | # ALTERNATIVE: Replacement Samples | 26 | # ALTERNATIVE: Replacement Samples |