[英]Saving a txt file using Pandas
I used pandas to replace the blank column spaces with nan in a txt file named A_B_1. 我用熊猫在名为A_B_1的txt文件中用nan替换了空白列。 How can I save this txt file as it is (blank spaces replaced with nan) to some path using pandas?
如何使用熊猫将这个txt文件保存为空白(用nan替换空格)? I used the following code to read from it:
我使用以下代码从中读取:
import pandas as pd
data= pd.read_table("/Users/Hrihaan/Desktop/Code/A_B_1.txt", sep="\s+", header=None).values
假设data
是2D numpy数组,您首先将其转换为pandas数据框,然后使用df.to_csv
并传递一个制表符分隔符:
pd.DataFrame(data).to_csv('out.csv', sep='\t')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.