Select DataFrame Columns
Build a DataFrame from records and return only the columns named in columns, as a list of row dictionaries. Keep row order and the requested column order. Every requested column exists in each non-empty input row. Empty records return an empty list.
Difficulty: beginner
Show hint
Use df.loc[:, columns] or df[columns], then to_dict(orient="records"). For empty input, a DataFrame constructed with columns=columns still has the required columns.
Examples
[[{"name":"Asha","score":82,"city":"Pokhara"},{"name":"Ben","score":0,"city":"Lalitpur"}],["name","score"]][{"name":"Asha","score":82},{"name":"Ben","score":0}]