简体   繁体   中英

Extract specific values from a column through pandas

I have a vcf file which contains multiple columns: Columns 1

INFO Columns contain multiple values in dictionary: INFO 2

I just want to extract "AF" values from INFO Column and make plot against chromosome. How can I do this?

You can use apply function to extract values from pandas column

import pandas as pd


# Sample data
df = pd.DataFrame({"INFO": [{"AF": [0.133], "AC": [35], "AN": 264}, {"AF": [0.007353], "AC": [2], "AN": 272}, {"AF": [0.026], "AC": [7], "AN": 272}], "POS": [50041, 50047, 50072]})

df["AF"] = df["INFO"].apply(lambda x: x["AF"])
print(df)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM