samedi 23 juillet 2016

Creating a Pandas dataframe from elements of a dictionary

I'm trying to create a pandas dataframe from a dictionary. The dictionary is set up as

nvalues = {"y1": [1, 2, 3, 4], "y2": [5, 6, 7, 8], "y3": [a, b, c, d]}

I would like the dataframe to include only "y1" and "y2". So far I can accomplish this using

df = pd.DataFrame.from_dict(nvalues)
df.drop("y3", axis=1, inplace=True)

I would like to know if it is possible to accomplish this without having df.drop()

Aucun commentaire:

Enregistrer un commentaire