teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

正規表現:」と”の間への空欄の追加

2017/11/20 06:23

投稿

syu-yu
syu-yu

スコア24

title CHANGED
File without changes
body CHANGED
@@ -12,7 +12,7 @@
12
12
  別ディレクトリ
13
13
  import re
14
14
  import pandas as pd
15
- pattern = re.compile('^\S+ \S+ \S+ [(.*)]"(.*)" (\S+) (\S+)$')
15
+ pattern = re.compile('^\S+ \S+ \S+ [(.*)] "(.*)" (\S+) (\S+)$')
16
16
  def parse_access_log(path):
17
17
  for line in open(path):
18
18
  for m in pattern.finditer(line):

1

不明点の追加

2017/11/20 06:23

投稿

syu-yu
syu-yu

スコア24

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,8 @@
1
1
  やりたいこと:txtファイルからアクセスログを読み込み、'time','request','status','bytes'のカラムにてデータフレーム化
2
2
 
3
- つまづいていること:
3
+ 不明点:
4
- エラー:DataFrame constructor not properly called!の表示になってしまうこと。
4
+ エラー:Shape of passed values is (1, 2), indices imply (4, 2)
5
+ ⓶ここでのyeildの意味。(検索してもイマイチ理解ができませんでした。)
5
6
 
6
7
  現状:
7
8
  access_log.txt
@@ -15,11 +16,7 @@
15
16
  def parse_access_log(path):
16
17
  for line in open(path):
17
18
  for m in pattern.finditer(line):
18
- return m.group()
19
+ yeild m.group()
19
20
 
20
21
  columns = ['time','request','status','bytes']
21
- pd.DataFrame(parse_access_log('access_log.txt'),columns=columns)
22
+ pd.DataFrame(parse_access_log('access_log.txt'),columns=columns)
22
-
23
- 出力が
24
- DataFrame constructor not properly called!
25
- になってしまいます。