Issue
I am having a weird error when selecting multiple columns in pandas dataframe. Here is the code:
import pandas as pd
df = pd.read_csv("./Dataset/train.csv", engine='python')
df['eviv1', 'v2a1']
I get this error message: KeyError: ('eviv1', 'v2a1')
but I don't get an error message when running
df['eviv1']
df[v2a1]
separately. PS: I am using python 3 and Jupyter Notebook with pandas version 0.23.0.
Solution
The column names (which are strings) cannot be sliced in the manner you tried. Please try this,
df[['eviv1', 'v2a1']]
Answered By - jits_on_moon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.