Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b33ed2

Browse files
committed
dp
1 parenta6ad2f2 commit7b33ed2

File tree

23 files changed

+2634
-1
lines changed

23 files changed

+2634
-1
lines changed

‎data/btc_apr_1_2012_to_apr_14_2019.csv‎

Lines changed: 2571 additions & 0 deletions
Large diffs are not rendered by default.

‎data/formats/csv_format.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# READ
2+
3+
# into pandas DataFrame
4+
importpandasaspd
5+
6+
btc=pd.read_csv('btc_daily.csv')
7+
print(btc.dtypes)
8+
print(btc['Price'])
9+
btc['Price']=btc['Price'].apply(lambdap:p.replace(',',''))
10+
btc['Price']=btc['Price'].apply(Decimal)# avoid float imprecision
11+
btc['Price']=btc['Price'].apply(lambdap:round(p,2))
12+
print(btc['Price'])
13+
14+
# process using standard csv
15+
16+
importcsv
17+
withopen('stocks.csv')asf:
18+
f_csv=csv.DictReader(f)
19+
forrowinf_csv:
20+
# process row
21+
# access using row header (row['Symbol'])
22+
23+
24+
# WRITE
25+
headers= ['Symbol','Price']
26+
rows= [('AA',13.87), ('AIG',35.65)]
27+
withopen('stocks.csv')asf:
28+
f_csv=csv.writer(f)
29+
f_csv.writerow(headers)
30+
f_csv.writerows(rows)
31+
32+
# if data is series of dicts
33+
headers= ['Symbol','Price']
34+
rows= [{'Symbol':'AA','Price':13.87}, {'Symbol':'AIG','Price':35.65}]
35+
withopen('stocks.csv','w')asf:
36+
f_csv=csv.DictWriter(f,headers)
37+
f_csv.writeheader()
38+
f_csv.writerows(rows)
File renamed without changes.

‎data/formats/yaml_format.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
importyaml
2+
withopen('tree.yaml')asf:
3+
# use safe_load instead load
4+
dataMap=yaml.safe_load(f)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp