Created
September 21, 2024 08:13
-
-
Save eugen-hoppe/049c3e0d3d9c7c2f85ec2d2fb214eeaf to your computer and use it in GitHub Desktop.
Create sample from CSV-file and save as CSV.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_sample_csv(path: str, name: str, rows: int, shuffle: int = 0) -> None: | |
| path_file_csv = f'{path}/' + name.removesuffix('.csv') + '.csv' | |
| input_df = pd.read_csv(path_file_csv) | |
| if bool(shuffle): | |
| input_df.sample(frac=1, random_state=shuffle) | |
| output_df = input_df.head(rows) | |
| output_df.to_csv(path_file_csv.replace('.csv', '_sample.csv'), index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment