【问题标题】:Python Pandas how to check if a dataframe is saved correctly without loss of information?Python Pandas 如何在不丢失信息的情况下检查数据帧是否正确保存?
【发布时间】:2022-06-24 00:58:36
【问题描述】:

我有以日期时间为索引的数据框,它的形状是(1.7 million rows, 50 columns),我将它保存为.csv 文件。现在我要确保数据框保存正确,没有信息丢失或丢失信息。

我的支票是:

# save original dataframe
origdf.to_csv('/blawblaw.csv')

# again import the saved dataframe, this for cross check
imdf = pd.read_csv('/blawblaw.csv')

# Check1 to see both dataframes are same
origdf.shape
Out[79]: (1776798, 50)
imdf.shape
Out[79]: (1776798, 51)

#check2 
origdf['one_binarycolumn'].value_counts()
Out[]: 
True     1643769
False     133029
Name: one_binarycolumn, dtype: int64

indf['one_binarycolumn'].value_counts()
Out[]: 
True     1643769
False     133029
Name: one_binarycolumn, dtype: int64

我的问题是,有没有比我在这里做的更好的方法?

【问题讨论】:

    标签: python pandas dataframe numpy


    【解决方案1】:

    尝试保存

    pd.to_csv('/blawblaw.csv', index=False)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 2018-05-25
      • 2022-12-14
      相关资源
      最近更新 更多