iT邦幫忙

0

存在兩種分隔符號delimiter,資料前處理

  • 分享至 

  • xImage

DATA如下,想請問
我的程式碼,透過sep='\t'

import pandas as pd

df = pd.read_csv(r'test.txt', encoding='utf-8', sep="\t", header=None)
print(df.head())

OUTPUT:
https://ithelp.ithome.com.tw/upload/images/20210825/20119920Ip9fItEjp5.png

若是我想要同時把前面透過\t切,後面又透過,切,切好後成一筆資料,這樣要怎麼撰寫程式碼。

謝謝,DATA如下

DATA:

2021/03/30 08:45:35	CD2	M,3500-N1-70-BB,0,553850,41275,183,15226,-6737450
2021/03/30 08:45:35	STD2	N,21966150,21963900,21964200
2021/03/30 08:45:35	ACD2	4955,4951,4951,2970
2021/03/30 08:44:07	AB1	M,2000-N1-50-DD,0,751350,56297,247,15281,-6541700
2021/03/30 08:44:06	STD1	N,21825500,21823500,21823400
2021/03/30 08:44:06	ACD1	4945,4941,4941,2964
2021/03/30 08:41:53	FAT	COMPLETE,1,0,1
2021/03/30 08:41:07	SP	RESUME_PROCESS,FULL_AUTO,1,0,1
2021/03/30 08:39:47	CAN	002,120,800,0,0,60,1800,MIX_FLUID
2021/03/30 08:36:01	CUT_HA_SN	14599,0,2951,0
2021/03/30 08:36:01	CUT	002,5489,37302,148,37302,148,OK,300,177,85,A
2021/03/30 08:34:55	NG2	112,OK XY2:Line=34,39547,230,-10,130,250,20,0,256,201413750
2021/03/30 08:34:55	KFCFLAG	1,1,2,KERF200 0 0 Z2 2
2021/03/30 08:34:44	KC1	178,OK XY2:Line=38,55524,290,20,140,260,20,0,0,0
2021/03/30 08:34:44	KFCFLAG	1,1,2,KERF200 0 0 Z1 2
2021/03/30 08:34:26	OPENKFC	2,2,2,2,0,0,1,1
2021/03/30 08:33:41	CD2	N,3500-N1-70-BB,0,556600,38722,171,15224,-6741950
2021/03/30 08:33:41	AB1	N,2000-N1-50-DD,0,758600,54826,239,15274,-6546600
2021/03/30 08:33:40	STD2	N,21967250,21965950,21965950
2021/03/30 08:33:40	STD1	N,21823500,21821100,21821050
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
Lin2602
iT邦新手 5 級 ‧ 2021-08-26 08:22:15

這樣?

df2 = [i.split(",") for i in df]
0
paicheng0111
iT邦大師 5 級 ‧ 2021-08-26 08:23:39

,再切一次

我要發表回答

立即登入回答