Skip to content

Commit 158e4b7

Browse files
committed
Sum all columns example
1 parent 4778c46 commit 158e4b7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Here's what you can find here:
7676
## [Data Science](/data_science/)
7777
- [Load CSV into a pandas dataframe](/data_science/load_csv.py)
7878
- [Group data and then find statistics for each group](/data_science/stats_by_group.py)
79+
- [Sum every column](/data_science/sum_columns.py) Load data and sum all columns
7980

8081
## Databases
8182
- [Neo4j](/databases/neo4j/)

data_science/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ Data science uses computer science and math to extract knowledge and information
66

77
- [Load CSV into a pandas data frame](/data_science/load_csv.py) Load data from the outside world
88
- [Group data and then find statistics for each group](/data_science/stats_by_group.py) Perform aggregate calculations on subsets of the data
9+
- [Sum every column](/data_science/sum_columns.py) Load data and sum all columns
910

1011
**[Back to start](https://github.com/ccozad/python-playground)**

data_science/sum_columns.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pandas as pd
2+
3+
# Put your own CSV file name here
4+
df = pd.read_csv('tshirts.csv')
5+
6+
numeric_columns = df.select_dtypes(include=[int, float])
7+
column_sums = numeric_columns.sum(axis=0)
8+
9+
# Remove the integer cast if you want to deal with floats
10+
column_sums = column_sums.astype(int)
11+
print(column_sums)

0 commit comments

Comments
 (0)