嗨,我有一些csv格式的数据。
我有一些非常简单的代码,只是要删除第一行:
import numpy as np
import pandas as pd
data = pd.read_csv("mydata.csv")
data = data.drop(data.columns[[0]],axis=0)
data.to_csv("mydata2.csv")
但是在运行时,我会收到此错误:
Warning (from warnings module):
File "C:/Users/george/Desktop/testing/output/PIVOTING.py", line 1
DtypeWarning: Columns (6) have mixed types. Specify dtype option on import or set low_memory=False.
Traceback (most recent call last):
File "C:/Users/george/Desktop/testing/output/PIVOTING.py", line 5, in <module>
data = data.drop(data.columns[[0]],axis=0)
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 3697, in drop
errors=errors)
File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 3111, in drop
obj = obj._drop_axis(labels, axis, level=level, errors=errors)
File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 3143, in _drop_axis
new_axis = axis.drop(labels, errors=errors)
File "C:\Python27\lib\site-packages\pandas\core\indexes\base.py", line 4404, in drop
'{} not found in axis'.format(labels[mask]))
KeyError: "['C'] not found in axis"
答案 0 :(得分:1)
熊猫skiprows
接受content = open('Hello.txt' , 'r')
for x in content:
a = str(x.strip())
print(a)
content.close()
来帮助完成这项任务,以供将来参考,here