I'm parsing several csv files with Pandas and the concatenating them into one big dataframe. Then, I want to groupby and calculate the mean().
Here's a sample dataframe:
df1.head()
Time Node Packets
0 1 0 0
2 1 1 0
4 1 2 0
6 1 3 0
8 1 4 0
df1.info(verbose=True)
<class 'pandas.core.frame.DataFrame'>
Int64Index: 27972 entries, 0 to 55942
Data columns (total 3 columns):
Time 27972 non-null int64
Node 27972 non-null int64
Packets 27972 non-null int64
dtypes: int64(3)
memory usage: 874.1 KB
None
Then I concatenate them (for the sake of simplicity, three dataframes)
df_total = pd.concat([df1, df2, df3])
df_total.info(verbose=True) results in
<class 'pandas.core.frame.DataFrame'>
Int64Index: 83916 entries, 0 to 55942
Data columns (total 3 columns):
Time 83916 non-null object
Node 83916 non-null object
Packets 83916 non-null object
dtypes: object(3)
memory usage: 2.6+ MB
None
Finally, I try :
df_total = df_total.groupby(['Time'])['Packets'].mean()
and that's where the error pandas.core.base.DataError: No numeric types to aggregate appears.
While I understand from other posts such as this that Pandas changes the dtype because of the non-null, I couldn't solve my issue with the proposed solutions.
How do I fix this?