简体   繁体   中英

How to separate columns when converting .txt file to csv

My.txt file looks like this

Text File

This is my code

import pandas as pd

df = pd.read_csv("Chilled Water Data/Sec_CW_BTUs.txt")

df.to_csv("Chilled Water Data/NEWSec_CW_BTUs.csv"

df.to_csv("Chilled Water Data/NEWSec_CW_BTUs.csv")

I am unsure how I can seperate/create colums when converting (also this file is to large to convert in excel).

Funny, but you need to look at something that my nickname suggests, but widely referred to as sep . Specifically, set a separator to what you believe separates the columns.

df = pd.read_csv("Chilled Water Data/Sec_CW_BTUs.txt", sep=" ")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM