Parsing Csv File Using Panda
I have been using matplotlib for quite some time now and it is great however, I want to switch to panda and my first attempt at it didn't go so well. My data set looks like this: s
Solution 1:
You can read a csv without headers:
data=pd.read_csv(filepath, header=None)
Columns will be numbered starting from 0. Selecting and filtering:
all_summers = data[data[0]=='summer']
If you want to do some operations grouping by the first column, it will look like this:
data.groupby(0).sum()
data.groupby(0).count()
...
Selecting a row after grouping:
sums = data.groupby(0).sum()
sums.loc['sam']
Plotting example:
sums.plot()
import matplotlib.pyplotas plt
plt.show()
For more details about plotting, see: http://pandas.pydata.org/pandas-docs/version/0.18.1/visualization.html
Solution 2:
df = pd.read_csv(filepath, header=None)
mike = df[df[0]=='mike'].values.tolist()
winter = df[df[0]=='winter'].values.tolist()
Then you can plot those list as you wanted to above
fig1 = plt.figure(figsize= (10,10))
ax = fig1.add_subplot(211)
ax.plot(mike, winter, label='Mike vs Winter speed', color = 'red')
Post a Comment for "Parsing Csv File Using Panda"