繁体   English   中英

无法在 pandas python 中的 CSV 中删除具有不同表格式的行

[英]Unable to delete row with different table format in CSV in pandas python

我在CSV中播放一些数据。

我想删除文件中的“时间戳是 UTC 时区”和“https://www.CryptoDataDownload.com”。 我一直试图通过drop()删除 pandas 中的这些项目并调整轴,label 和其他一些参数但没有用。 由于这些项目的那一行没有 label,所以我不能通过 label 真正做到 go。 我发现了一些需要创建列表来处理的其他帖子(例如这篇文章),或者通过import csv (例如这篇文章)来创建 go。 但我只是想知道是否可以通过 pandas 做到这一点? 由于这将是一个包含许多 CSV 的重复过程,因此它将花费资源到 go 到 csv package(我猜?)。

我真正想要做的是删除列“Unix Timestamp”并将“Date”更改为“datetime_UTC”,以便我可以转换“Date”中的日期时间格式(似乎我不能使用名称“Date”就我到目前为止所做的那样,在 pandas 中转换日期时间格式)。 但是“时间戳是 UTC 时区”和“https://www.CryptoDataDownload.com”已阻止处理 pandas 中的列删除。

非常感谢!

在这种示例文件的情况下,使用pd.read_csv方法的关键字skiprows就足够了

import pandas as pd
df = pd.read_csv('https://www.cryptodatadownload.com/cdd/Okcoin_BTCUSD_1h.csv', skiprows=1)

运行此代码方法df.info()后呈现以下结果:

<class 'pandas.core.frame.DataFrame'>  
RangeIndex: 29650 entries, 0 to 29649  
Data columns (total 9 columns):  
Unix Timestamp    29650 non-null float64  
Date              29650 non-null object  
Symbol            29650 non-null object  
Open              29650 non-null float64  
High              29650 non-null float64  
Low               29650 non-null float64  
Close             29650 non-null float64  
Volume BTC        29650 non-null float64  
Volume USD        29650 non-null float64  
dtypes: float64(7), object(2)   
memory usage: 2.0+ MB  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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