i have a large size csv file which i want to split : import pandas as pd Replace…
- User
i have a large size csv file which i want to split : import pandas as pd
Replace ‘your_large_file.csv’ with the path to your large CSV file
input_csv = r’C:\Users\arisa\Desktop\combined_day_fl_1hot_custom_extra_and_indic.csv’
This will be the new file with 0.06% of the original data
output_csv = r’C:\Users\arisa\Desktop\combined_day_fl_1hot_custom_extra_and_indic_val.csv’
Adjust this variable for different percentages
fraction_of_interest = 0.06 / 100 # 0.06%
Read the large CSV file
df = pd.read_csv(input_csv)
Sample 0.06% of the rows randomly without replacement
sampled_df = df.sample(frac=fraction_of_interest, random_state=1) # random_state for reproducibility
Write sampled rows to a new CSV file
sampled_df.to_csv(output_csv, index=False) # index=False to avoid writing row indices
print(f’Successfully saved {len(sampled_df)} rows to “{output_csv}”‘)
error:
import pandas as pd
Replace ‘your_large_file.csv’ with the path to your large CSV file
input_csv = r’C:\Users\arisa\Desktop\combined_day_fl_1hot_custom_extra_and_indic.csv’
This will be the new file with 0.06% of the original data
output_csv = r’C:\Users\arisa\Desktop\combined_day_fl_1hot_custom_extra_and_indic_val.csv’
Adjust this variable for different percentages
fraction_of_interest = 0.06 / 100 # 0.06%
Read the large CSV file
df = pd.read_csv(input_csv)
Sample 0.06% of the rows randomly without replacement
sampled_df = df.sample(frac=fraction_of_interest, random_state=1) # random_state for reproducibility
Write sampled rows to a new CSV file
sampled_df.to_csv(output_csv, index=False) # index=False to avoid writing row indices
print(f’Successfully saved {len(sampled_df)} rows to “{output_csv}”')
- Assistant
It looks like you are encountering an issue but haven't explicitly mentioned what the error message or problem is. However, I noticed that in your code snippets, there are some typographic (quotation mark) errors that might be causing issues, particularly with the path strings and the print function. This could lead to syntax errors or unexpected behavior when running your code.