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

回答編集履歴

2

方法

2021/10/07 07:14

投稿

Eurus
Eurus

スコア15

answer CHANGED
@@ -4,4 +4,18 @@
4
4
  with open('パス.txt', 'w') as f:
5
5
  for i in df['列名']:
6
6
  f.write("%s\n" % i)
7
+ ```
8
+
9
+ ーーー更新ーーー
10
+ Stack OverFlowで次の方法を見つけました
11
+
12
+ https://stackoverflow.com/questions/47339698/how-to-convert-csv-file-to-text-file-using-python
13
+ ```python
14
+ import csv
15
+ csv_file = raw_input('Enter the name of your input file: ')
16
+ txt_file = raw_input('Enter the name of your output file: ')
17
+ with open(txt_file, "w") as my_output_file:
18
+ with open(csv_file, "r") as my_input_file:
19
+ [ my_output_file.write(" ".join(row)+'\n') for row in csv.reader(my_input_file)]
20
+ my_output_file.close()
7
21
  ```

1

誤字

2021/10/07 07:14

投稿

Eurus
Eurus

スコア15

answer CHANGED
@@ -1,4 +1,4 @@
1
- csvの列数は幾つがありますか?一なら,下のコードで行けると思います.
1
+ csvの列数は幾つがありますか?一なら,下のコードで行けると思います.
2
2
 
3
3
  ```python
4
4
  with open('パス.txt', 'w') as f: