-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_parser.py
43 lines (38 loc) · 1.18 KB
/
csv_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import matplotlib.pyplot as plt
import pandas as pd
# %matplotlib inline # for Jupyter Notebook/Console, but not for terminal
import click
@click.group()
def cli():
"""Can display and plot csv files."""
pass
@cli.command()
@click.argument('filename')
def display(filename):
"""Displays the column names and their data type."""
df = pd.read_csv(filename)
print(df.dtypes)
@cli.command()
@click.argument('filename')
@click.option('--column', default=None, help="Name of column to plot. If not used, all will be plotted.")
def plot(filename, column):
"""Plots a histogram of a column of the csv file."""
df = pd.read_csv(filename)
if column is None:
df.hist()
else:
df.hist(column=column);
plt.show() # for terminal
if __name__ == '__main__':
cli()
# import sys
# command = sys.argv[1]
# filename = sys.argv[2]
# if command == 'display':
# display_columns(filename)
# elif command == 'plot':
# plot_hist(filename)
# else:
# raise IOError("csv_parser requires 'plot' or 'display' commands")
# df.plot(kind='scatter', x='bier_preis', y='bier_konsum')
# df.plot(kind='scatter', x='jahr', y='bier_preis')