I am trying to extract a subset of my dataframe. For example, I have a df:
df = {'a':[1,2,3,4,5,6],
'b':[43,34,65,56,29,76],
'c':[65,67,78,65,45,52]}
Assume this data has been converted to a dataframe using pandas.
Now suppose I want just a and b:
new_df = df['a','b']
For some reason with my df, I get a KeyError. However, if I did:
new_df = df['a']
OR
new_df = df['b']
I get a new df with a or b. I only get the KeyError when I try to extract both columns at once.
Can someone help me get past this KeyError? I've searched multiple forums and there have been other KeyError posts but nothing that helped me so far.
Please note my dataframe is only an example. My actual dataframe is a csv file that was converted to a dataframe using pd.read_csv.
Also, I am not the best when it comes to Python.