Last active
January 2, 2021 18:30
-
-
Save shks/05d795cfd6fef945313a9150cf8c5840 to your computer and use it in GitHub Desktop.
read_tsv_csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tsv, csvファイルからデータの読み込み | |
def readFile(filePath): | |
#TSVの場合#delimiter="\t" | |
#CSVの場合"," | |
_d= "\t"#"," | |
#skiprows=1 : 最初の行を無視する | |
_data = np.loadtxt(filePath,delimiter = _d,skiprows=1) | |
#データ列に名前をつける | |
columns = ['AAAA','BBBBBB', 'CCCCC', 'DDDDD', 'EEEEE'] | |
_df = pd.DataFrame(data=_data, columns=columns, dtype='float') | |
return _df | |
#複数のtsvを読んで、1つのDFへ統合 | |
def readFilesIntoOnePD(filePaths): | |
allData_np = np.empty((0 , 5)) | |
for f in filePaths: | |
print(f) | |
_d= "\t" | |
_data = np.loadtxt(f,delimiter = _d,skiprows=1) | |
allData_np = np.vstack( (allData_np, _data)) | |
columns = ['AAAA','BBBBBB', 'CCCCC', 'DDDDD', 'EEEEE'] | |
_df = pd.DataFrame(data=allData_np, columns=columns, dtype='float') | |
return _df | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment