-
-
Save taojy123/1a4624c7dd1c4ee33ba3f5c2fb0b188a to your computer and use it in GitHub Desktop.
Pandas 代码小示例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
df = pd.read_csv('pandasTest.csv') | |
print(df) | |
print('================================================================') | |
# 1 | |
print( df.loc[:,['OrderDate', 'Item']] ) | |
# 2 | |
print( pd.concat([df.loc[4:5,['Units', 'Unit Cost']], df.loc[2:2,['Units', 'Unit Cost']]]) ) | |
# 3 | |
print( df[df['Unit Cost'] > 50] ) | |
# 4 | |
print( df[df['Unit Cost'] > 15][df['Unit Cost'] < 20] ) | |
# 5 | |
print( df[df.Region == 'Central'][df.Item == 'Binder'] ) | |
# 6 | |
print( 'Sum is: %s' % df.sum()['Units'] ) | |
# 7 | |
print( df.groupby('Region').mean().loc[:,['Unit Cost']] ) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OrderDate | Region | Rep | Item | Units | Unit Cost | Total | |
---|---|---|---|---|---|---|---|
1/6/16 | East | Jones | Pencil | 95 | 1.99 | 189.05 | |
1/23/16 | Central | Kivell | Binder | 50 | 19.99 | 999.50 | |
2/9/16 | Central | Jardine | Pencil | 36 | 4.99 | 179.64 | |
2/26/16 | Central | Gill | Pen | 27 | 19.99 | 539.73 | |
3/15/16 | West | Sorvino | Pencil | 56 | 2.99 | 167.44 | |
4/1/16 | East | Jones | Binder | 60 | 4.99 | 299.40 | |
4/18/16 | Central | Andrews | Pencil | 75 | 1.99 | 149.25 | |
5/5/16 | Central | Jardine | Pencil | 90 | 4.99 | 449.10 | |
5/22/16 | West | Thompson | Pencil | 32 | 1.99 | 63.68 | |
6/8/16 | East | Jones | Binder | 60 | 8.99 | 539.40 | |
6/25/16 | Central | Morgan | Pencil | 90 | 4.99 | 449.10 | |
7/12/16 | East | Howard | Binder | 29 | 1.99 | 57.71 | |
7/29/16 | East | Parent | Binder | 81 | 19.99 | 1,619.19 | |
8/15/16 | East | Jones | Pencil | 35 | 4.99 | 174.65 | |
9/1/16 | Central | Smith | Desk | 2 | 125.00 | 250.00 | |
9/18/16 | East | Jones | Pen Set | 16 | 15.99 | 255.84 | |
10/5/16 | Central | Morgan | Binder | 28 | 8.99 | 251.72 | |
10/22/16 | East | Jones | Pen | 64 | 8.99 | 575.36 | |
11/8/16 | East | Parent | Pen | 15 | 19.99 | 299.85 | |
11/25/16 | Central | Kivell | Pen Set | 96 | 4.99 | 479.04 | |
12/12/16 | Central | Smith | Pencil | 67 | 1.29 | 86.43 | |
12/29/16 | East | Parent | Pen Set | 74 | 15.99 | 1,183.26 | |
1/15/17 | Central | Gill | Binder | 46 | 8.99 | 413.54 | |
2/1/17 | Central | Smith | Binder | 87 | 15.00 | 1,305.00 | |
2/18/17 | East | Jones | Binder | 4 | 4.99 | 19.96 | |
3/7/17 | West | Sorvino | Binder | 7 | 19.99 | 139.93 | |
3/24/17 | Central | Jardine | Pen Set | 50 | 4.99 | 249.50 | |
4/10/17 | Central | Andrews | Pencil | 66 | 1.99 | 131.34 | |
4/27/17 | East | Howard | Pen | 96 | 4.99 | 479.04 | |
5/14/17 | Central | Gill | Pencil | 53 | 1.29 | 68.37 | |
5/31/17 | Central | Gill | Binder | 80 | 8.99 | 719.20 | |
6/17/17 | Central | Kivell | Desk | 5 | 125.00 | 625.00 | |
7/4/17 | East | Jones | Pen Set | 62 | 4.99 | 309.38 | |
7/21/17 | Central | Morgan | Pen Set | 55 | 12.49 | 686.95 | |
8/7/17 | Central | Kivell | Pen Set | 42 | 23.95 | 1,005.90 | |
8/24/17 | West | Sorvino | Desk | 3 | 275.00 | 825.00 | |
9/10/17 | Central | Gill | Pencil | 7 | 1.29 | 9.03 | |
9/27/17 | West | Sorvino | Pen | 76 | 1.99 | 151.24 | |
10/14/17 | West | Thompson | Binder | 57 | 19.99 | 1,139.43 | |
10/31/17 | Central | Andrews | Pencil | 14 | 1.29 | 18.06 | |
11/17/17 | Central | Jardine | Binder | 11 | 4.99 | 54.89 | |
12/4/17 | Central | Jardine | Binder | 94 | 19.99 | 1,879.06 | |
12/21/17 | Central | Andrews | Binder | 28 | 4.99 | 139.72 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment