0

I have error to select my columns hours and game

I have tried different codes but none of them are working.

import pandas as pd
import numpy as np

# upload the dataset to spyder
data = pd.read_csv("C:/Users/User/Documents/FYP II/gamedataset.csv")

# Data selection on columns needed for data mining

collect =  data[['Game','Genre','price','Hours','Day.period','Age','Gender','Violence.Rate','Cause.gaming','CID.Rating',]]

i expect a dataset collect to show

i get:

KeyError: "['Hours', 'Game'] not in index

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • show the .csv... – eyllanesc Oct 03 '19 at 04:01
  • (Or a portion of the dataframe.) – Mateen Ulhaq Oct 03 '19 at 04:03
  • Add output of `data.columns` – Vishnudev Krishnadas Oct 03 '19 at 04:06
  • 1
    Ensure that there are no spaces before/after the column name. – Vishnudev Krishnadas Oct 03 '19 at 04:09
  • 2
    Hi, and welcome to Stack OVerflow. When asking a pandas question, please do not add screenshots; instead, create a minimal dataframe that reproduces the problem, and show that instead. In your example, show (with re-creating code) the first two or three rows of the dataframe and the relevant columns; you don't need a big dataframe to recreate the problem. To learn more, please visit: https://stackoverflow.com/help/how-to-ask, https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples, https://stackoverflow.com/help/minimal-reproducible-example – Itamar Mushkin Oct 03 '19 at 04:30
  • 1
    Check `data.columns` and compare 'Hours' and 'Game' column name. It is quite possible that there is an added space in column name. – Sumit S Chawla Oct 03 '19 at 06:26

0 Answers0