Sam
Sam

Reputation: 1256

How can I write this syntax if there is space in column name?

How can I write this syntax if there was space in the column name "image_path"? Instead of "image_path", I have "image path". I changed the column name so it works. However, I was wondering if there is any way I can write this syntax without changing column name from "image path" to "image_path".

(df.groupby('content_type').image_path.nunique())

Thank you, Shone

EDIT: Just in case the answer below is deleted:

df.groupby('content_type')['image path'].nunique()

Upvotes: 1

Views: 138

Answers (1)

cs95
cs95

Reputation: 402553

Use the [...] indexer with a string:

df.groupby('content_type')['image path'].nunique()

Upvotes: 4

Related Questions