KS Sample data analysis project
Data file from kaggle project.
Author: Avnit Bambah
Date : 04/04/2018
Learn how to plot in 2d and 3d.
Group by the data set and create reports.
%matplotlib inline
# modules we'll use
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# read in all our data
ks_data = pd.read_csv("data/ks-data.csv")
ks_data.head(10)
main_data = ks_data.groupby(['main_category','currency','pledged']).sum().fillna(0)
main_data.head(10)
| ID | goal | backers | usd pledged | usd_pledged_real | usd_goal_real | |||
|---|---|---|---|---|---|---|---|---|
| main_category | currency | pledged | ||||||
| Art | AUD | 0.0 | 85309221240 | 1951740.0 | 0 | 0.00 | 0.00 | 1674289.71 |
| 1.0 | 14270689056 | 1290631.0 | 13 | 7.66 | 10.55 | 989246.84 | ||
| 2.0 | 5306746742 | 25018100.0 | 9 | 8.07 | 7.88 | 19151082.36 | ||
| 3.0 | 808529669 | 30.0 | 1 | 2.82 | 2.80 | 27.96 | ||
| 5.0 | 6512118491 | 12700.0 | 7 | 18.39 | 25.53 | 10659.45 | ||
| 6.0 | 1683274517 | 1000.0 | 2 | 5.64 | 5.64 | 940.56 | ||
| 9.0 | 1203811075 | 500.0 | 2 | 8.38 | 8.42 | 467.60 | ||
| 10.0 | 9991481798 | 23475.0 | 9 | 74.88 | 74.72 | 20348.56 | ||
| 13.0 | 542029527 | 5000.0 | 2 | 12.16 | 11.99 | 4610.42 | ||
| 16.0 | 2812118558 | 100015.0 | 6 | 27.98 | 26.53 | 79045.65 |
grouped = ks_data.groupby('deadline').agg({"usd_pledged_real": [sum,min,max]})
grouped.head(10)
grouped.tail(10)
| usd_pledged_real | |||
|---|---|---|---|
| sum | min | max | |
| deadline | |||
| 2017-11-24 | 3555122.04 | 0.00 | 2209270.00 |
| 2017-11-25 | 1594187.93 | 0.00 | 424615.00 |
| 2017-11-26 | 630356.47 | 0.00 | 132795.34 |
| 2017-11-27 | 487843.91 | 0.00 | 84808.47 |
| 2017-11-28 | 955650.49 | 0.00 | 132246.00 |
| 2017-11-29 | 862662.23 | 0.00 | 147230.81 |
| 2017-11-30 | 2889150.20 | 0.00 | 552799.00 |
| 2017-12-01 | 4417653.57 | 0.00 | 901058.04 |
| 2017-12-02 | 1404655.77 | 0.00 | 308142.00 |
| 2017-12-03 | 1405305.66 | 0.00 | 525890.00 |
| 2017-12-04 | 1686918.43 | 0.00 | 319052.00 |
| 2017-12-05 | 1281472.11 | 0.00 | 333885.30 |
| 2017-12-06 | 1380214.37 | 0.00 | 193463.91 |
| 2017-12-07 | 4239030.75 | 0.00 | 1374021.00 |
| 2017-12-08 | 1569119.93 | 0.00 | 392050.00 |
| 2017-12-09 | 3614540.76 | 0.00 | 1059078.19 |
| 2017-12-10 | 1169818.59 | 0.00 | 336976.00 |
| 2017-12-11 | 776343.46 | 0.00 | 108671.00 |
| 2017-12-12 | 994899.16 | 0.00 | 169854.00 |
| 2017-12-13 | 1491456.65 | 0.00 | 490319.00 |
| 2017-12-14 | 3459127.75 | 0.00 | 905442.20 |
| 2017-12-15 | 2840262.83 | 0.00 | 299078.55 |
| 2017-12-16 | 1535061.83 | 0.00 | 200493.60 |
| 2017-12-17 | 3024527.28 | 0.00 | 959437.00 |
| 2017-12-18 | 930112.96 | 0.00 | 183672.00 |
| 2017-12-19 | 818062.72 | 0.00 | 290429.00 |
| 2017-12-20 | 1589046.53 | 0.00 | 215487.75 |
| 2017-12-21 | 2740310.61 | 0.00 | 300401.50 |
| 2017-12-22 | 1545897.78 | 0.00 | 264616.52 |
| 2017-12-23 | 1482775.77 | 0.00 | 312061.00 |
| ... | ... | ... | ... |
| 2018-02-02 | 56446.25 | 0.00 | 24849.00 |
| 2018-02-03 | 283099.38 | 0.00 | 270290.50 |
| 2018-02-04 | 24453.00 | 0.00 | 15166.00 |
| 2018-02-05 | 408851.98 | 0.00 | 336966.21 |
| 2018-02-06 | 154314.81 | 0.00 | 136755.34 |
| 2018-02-07 | 58141.35 | 0.00 | 42799.00 |
| 2018-02-08 | 10716.49 | 0.00 | 4086.48 |
| 2018-02-09 | 6759.43 | 0.00 | 2350.00 |
| 2018-02-10 | 50459.76 | 0.00 | 37697.00 |
| 2018-02-11 | 7667.67 | 0.00 | 2527.95 |
| 2018-02-12 | 273298.29 | 0.00 | 158883.48 |
| 2018-02-13 | 21042.33 | 0.00 | 19766.00 |
| 2018-02-14 | 7911.84 | 0.00 | 3127.00 |
| 2018-02-15 | 19487.17 | 3.99 | 13978.13 |
| 2018-02-16 | 64513.19 | 0.00 | 63444.59 |
| 2018-02-17 | 29025.43 | 0.00 | 12343.00 |
| 2018-02-18 | 2843.00 | 0.00 | 515.00 |
| 2018-02-19 | 4005.46 | 0.00 | 1608.15 |
| 2018-02-20 | 4720.61 | 0.00 | 2493.01 |
| 2018-02-21 | 10857.27 | 0.00 | 4886.00 |
| 2018-02-22 | 355.97 | 0.00 | 191.71 |
| 2018-02-23 | 11129.63 | 11.98 | 6894.99 |
| 2018-02-24 | 17328.00 | 0.00 | 15179.00 |
| 2018-02-25 | 1243.14 | 0.00 | 767.92 |
| 2018-02-26 | 1765.38 | 0.00 | 487.00 |
| 2018-02-27 | 436.73 | 0.00 | 430.00 |
| 2018-02-28 | 1323.80 | 0.00 | 1225.00 |
| 2018-03-01 | 57.36 | 1.00 | 50.00 |
| 2018-03-02 | 1518.19 | 0.00 | 557.80 |
| 2018-03-03 | 174.00 | 0.00 | 174.00 |
100 rows Ć 3 columns
plt.plot(grouped)
[<matplotlib.lines.Line2D at 0x151102828>,
<matplotlib.lines.Line2D at 0x150e655c0>,
<matplotlib.lines.Line2D at 0x150e6c668>]

plt.contour(grouped)
<matplotlib.contour.QuadContourSet at 0x15075c400>

3d ploting
from mpl_toolkits.mplot3d import axes3d from matplotlib import cm
fig = plt.figure() ax = fig.gca(projection=ā3dā) cset = ax.contour(grouped,grouped,grouped) plt.show()