I have a small dataframe, two columns wide. My goal is to split this dataframe into a list of dataframes, based on unique values from the QE column.
I can't seem to locate the error in my code.
Edited for clarity:
import pandas as pd
def Function1():
data = {'Name': ['Dave', 'Sue', 'John', 'Dave', 'Michael', 'Sue'],
'QE': ['12.31.2019', '12.31.2019', '12.31.2019', '03.31.2020', '03.31.2020', '03.31.2020']
}
df = pd.DataFrame(data, columns=['Name', 'QE'])
Quarters = list(df['QE'].unique())
dfs = []
for x in Quarters:
df = df[df['QE'] == x]
df = df['Name'].reset_index(drop=True)
dfs.append(df)
return df
a = Function1()
KeyError: 'QE'
QEis not there in your file. Which python version are you using? Running your code on python 2.7 with a simple csv file it works.df.columnsand see if it exists.