Python 如何清理数据,以便将其转换为csv文件
我有一个如下所示的文本文件。 我的问题是,有没有一种方法可以在不必手动清理数据的情况下将其转换为类似csv的数据格式Python 如何清理数据,以便将其转换为csv文件,python,pandas,Python,Pandas,我有一个如下所示的文本文件。 我的问题是,有没有一种方法可以在不必手动清理数据的情况下将其转换为类似csv的数据格式 Word, Hiragana, English 会う, あう -to meet 青, あお -blue 青い, あおい -blue 赤, あか -red 赤い, あかい -red 明い, あかるい -bright 秋, あき -autumn 開く, あく -to open,to become open
Word, Hiragana, English
会う, あう -to meet
青, あお -blue
青い, あおい -blue
赤, あか -red
赤い, あかい -red
明い, あかるい -bright
秋, あき -autumn
開く, あく -to open,to become open
開ける, あける -to open
上げる, あげる -to give
朝, あさ -morning
朝御飯, あさごはん -breakfast
あさって -day after tomorrow
足, あし -foot,leg
明日, あした -tomorrow
あそこ -over there
遊ぶ, あそぶ -to play,to make a visit
暖かい, あたたかい -warm
頭, あたま -head
新しい, あたらしい -new
あちら -there
暑い, あつい -hot
熱い, あつい -hot to the touch
厚い, あつい -kind, deep, thick
あっち -over there
在您的情况下,类似的操作应该会起作用:
for l in textfile:
split1 = l.split(',', 1) # split on first occurance of ',' in line
word = split1[0] # take the first argument of the split as word
split2 = split1[0].split('-', 1) # split the second part with first occurance of '-'
hiragana = split2[0]
english = split2[1]