我正在尝试合并两个具有相同列'Value'的数据集,但它给了我这个错误:无法将DataFrame与类型
的实例合并import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import pie, axis, show
from pandas import Series, DataFrame
class Dataset():
def __init__(self, input):
self.choice = input
self.file = 0
def read(self):
if self.choice == ("merge"):
self.file = pd.read_csv('bbc.csv')
self.file = pd.read_csv('cnn.csv')
print(pd.merge('bbc.csv', 'cnn.csv', on="Value"))
答案 0 :(得分:1)
您已将两个打开的.csv定义为self.file ...然后您尝试合并两个字符串。相反,将数据帧定义为变量然后合并:
if self.choice == ("merge"):
self.file1 = pd.read_csv('bbc.csv')
self.file2 = pd.read_csv('cnn.csv')
# print(pd.merge(self.file1, self.file2, on="Value"))
print(self.file1.merge(self.file2, how='inner', on="Value"))