将数据框保存到csv文件(python) [英] saving a dataframe to csv file (python)

查看:1625
本文介绍了将数据框保存到csv文件(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新构造我的降水数据在excel文件中的组织方式.为此,我编写了以下代码:

I am trying to restructure the way my precipitations' data is being organized in an excel file. To do this, I've written the following code:

import pandas as pd

df = pd.read_excel('El Jem_Souassi.xlsx', sheetname=None, header=None)
data=df["El Jem"]

T=[]
for column in range(1,56):
    liste=data[column].tolist()
    for row in range(1,len(liste)):
        liste[row]=str(liste[row])
        if liste[row]!='nan':
            T.append(liste[row])

result=pd.DataFrame(T)
result

这段代码可以正常工作,通过Jupyter,我可以看到结果很好 屏幕截图

This code works fine and through Jupyter I can see that the result is good screenshot

但是,尝试将此数据帧保存到csv文件时遇到问题.

However, I am facing a problem when attempting to save this dataframe to a csv file.

 result.to_csv("output.csv")

结果文件包含垂直索引列,看来我无法调用特定的单元格.

The resulting file contains the vertical index column and it seems I am unable to call for a specific cell.

(希望有人可以帮助我解决这个问题) 非常感谢!

(Hopefully, someone can help me with this problem) Many thanks !!

推荐答案

全部在您有兴趣跳过索引列,因此:

You are interested in skipping the index column, so do:

result.to_csv("output.csv", index=False)

如果您还想跳过标题,请添加:

If you also want to skip the header add:

result.to_csv("output.csv", index=False, header=False)

我不知道您的输入数据的样子(将其提供给您的问题是一个好主意).但是请注意,当前您可以通过执行以下操作来获得相同的结果:

I don't know how your input data looks like (it is a good idea to make it available in your question). But note that currently you can obtain the same results just by doing:

import pandas as pd
df = pd.DataFrame([0]*16)
df.to_csv('results.csv', index=False, header=False)

这篇关于将数据框保存到csv文件(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆