import pandas as pd from tqdm import tqdm print("Loading data...") df =…
- User
import pandas as pd from tqdm import tqdm
print("Loading data...") df = pd.read_csv('/kaggle/input/output-protein-homology/balanced_dataset_no_repeats_top40.csv') print(f"Loaded {len(df)} sequences from {df['super-family'].nunique()} superfamilies.")
i have this code to load there are 40 super families can you
- Assistant
You have code that loads a CSV with protein sequence data and prints how many sequences and superfamilies were loaded. You mentioned that there are 40 superfamilies.
How can I help you? For example, do you want to:
- Confirm that there really are 40 superfamilies?
- Show the number of sequences per superfamily?
- Split the dataset by superfamily?
- Perform some data processing or filtering grouped by superfamily?
- Visualize data distribution for these superfamilies?
- Something else?
Please clarify what exactly you'd like me to do with this data related to the 40 superfamilies.
- User
Loading data... Loaded 165197 sequences from 40 superfamilies.
i am getting this output from this from this code
import pandas as pd from tqdm import tqdm
print("Loading data...") df = pd.read_csv('/kaggle/input/output-protein-homology/balanced_dataset_no_repeats_top40.csv') print(f"Loaded {len(df)} sequences from {df['super-family'].nunique()} superfamilies.")
so tell me can you just take 3000 sequences from each classes
- Assistant
Yes, you can sample 3000 sequences from each of the 40 superfamilies (classes) using pandas. Here's how you can do it:
import pandas as pd print("Loading data...") df = pd.read_csv('/kaggle/input/output-protein-homology/balanced_dataset_no_repeats_top40.csv') print(f"Loaded {len(df)} sequences from {df['super-family'].nunique()} superfamilies.") # Group by 'super-family' and sample 3000 from each group (if group size >= 3000) sampled_df = df.groupby('super-family').apply(lambda x: x.sample(n=3000, random_state=42) if len(x) >= 3000 else x).reset_index(drop=True) print(f"Sampled dataset size: {len(sampled_df)} sequences") print(sampled_df['super-family'].value_counts())Explanation:
groupby('super-family'): groups sequences by their superfamily.- The
applylambda function samples 3000 sequences if the group has at least 3000, or takes the whole group if less. random_state=42: ensures reproducible sampling.reset_index(drop=True): resets the index after grouping.
Let me know if you want me to save this sampled DataFrame or do further operations!