以-为分隔符,找出-后面的数字有多少个不同的

adata.obs.index.str.split("-").str[1].unique()

import pandas as pd

# Load the index into a Pandas Series object
index = pd.Series(['p1_1_AAACCTGAGTCAAGCG-1', 'p1_1_AAACCTGCAAATTGCC-1',
                   'p1_1_AAACCTGGTAGGAGTC-1', 'p1_1_AAACGGGAGATGTAAC-1',
                   'p1_1_AAACGGGAGCTGCAAG-1', 'p1_1_AAAGATGAGAAGGTTT-1',
                   'p1_1_AAAGATGCAATAACGA-1', 'p1_1_AAAGATGCAATGAATG-1',
                   'p1_1_AAAGATGCAGACTCGC-1', 'p1_1_AAAGATGCAGTCAGCC-1',
                   'p9_TTTGCGCTCTGAAAGA-1', 'p9_TTTGGTTGTCTCTTTA-1',
                   'p9_TTTGGTTTCTGATACG-1', 'p9_TTTGTCAAGAGGTTGC-1',
                   'p9_TTTGTCAAGATATACG-1', 'p9_TTTGTCAAGGCGTACA-1',
                   'p9_TTTGTCACAGGAACGT-1', 'p9_TTTGTCACATCCCACT-1',
                   'p9_TTTGTCAGTTGTCGCG-1', 'p9_TTTGTCATCAAACCAC-1'])

# Extract the digits after the hyphen and store them in a new Series
digits = index.str.split('-').str[1]

# Count the number of unique digits using the nunique() function
num_unique_digits = digits.nunique()

print("Number of unique digits after hyphen: ", num_unique_digits)


Number of unique digits after hyphen:  1

猜你喜欢

转载自blog.csdn.net/qq_52813185/article/details/129805275