Skip to content

Instantly share code, notes, and snippets.

@eugen-hoppe
Created September 21, 2024 08:13
Show Gist options
  • Select an option

  • Save eugen-hoppe/049c3e0d3d9c7c2f85ec2d2fb214eeaf to your computer and use it in GitHub Desktop.

Select an option

Save eugen-hoppe/049c3e0d3d9c7c2f85ec2d2fb214eeaf to your computer and use it in GitHub Desktop.
Create sample from CSV-file and save as CSV.
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