简体   繁体   中英

How do I read only specific columns from a JSON dataframe?

I have a JSON dataframe with 12 columns, however, I only want to read columns 2 and 5 which are named "name" and "score."

Currently, the code I have is:

df = pd.read_json("path",orient='columns', lines=True)

print(df.head())

What that does is displays every column, as would be expected.

After reading through the documentation here:

https://pandas.pydata.org/docs/reference/api/pandas.read_json.html

I can't find any real way to only parse certain columns within json, compared to csv where you can parse columns using names=[]

pass a list of columns for indexing

df[["name","score"]]

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