例如,csv文件如下,(1,2,3)是标题!
1,2,3
0,0,0
Run Code Online (Sandbox Code Playgroud)
我使用pd.read_csv读取csv文件并打印
import pandas as pd
df = pd.read_csv('./test.csv')
print(df[1])
Run Code Online (Sandbox Code Playgroud)
发生错误 key error:1
似乎该read_csv解析标头为字符串。
有什么办法在数据框列中使用整数类型?
例如,两个数据框如下
df1
index a b
0 1 1
1 1 1
Run Code Online (Sandbox Code Playgroud)
df2
index a b
1 2 2
2 2 2
Run Code Online (Sandbox Code Playgroud)
我想df1.append(df2)覆盖
所以结果可能如下
合并df
index a b
0 1 1
1 2 2 <= overwrite value of df2
2 2 2
Run Code Online (Sandbox Code Playgroud)
大熊猫有什么好方法吗?