python - 如何清理我的数据,以便将其转换为 csv 文件
问题描述
我有一个如下所示的文本文件。我的问题是,有没有一种方法可以清理数据而无需手动执行,以便我可以将其转换为像 csv 这样的数据格式?
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]
推荐阅读
- d3.js - D3 svg插入问题
- excel - Excel VBA将带有变量的公式插入单元格
- java - 使用 WebSecurity.ignoring() 时如何修复 CORS
- grafana - Grafana 中显示的 netdata 指标显示不正确的值
- html - 如何针对 Web 布局问题模拟高分辨率显示
- android - 如何以编程方式更改进度条的进度值?
- javascript - 如何在 React 中将我的子组件移动到新的父组件?
- r - 带有标签的文本输出或不可编辑的文本输入
- python - 在 csv 文件中添加新列和来自不同词典理解的值
- kubernetes - 如何让 LetsEncrypt 在 Traefik 上使用通配符域?