我正在尝试对我的数据集使用 applymap 以将浮点数创建为整数。但是我收到“'Series' 对象没有属性'applymap'”错误。
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 == ("1"):
self.file = pd.read_csv('mycsv.csv')
self.file.plot(kind='bar')
print(df)
self.file['Value'].applymap(float)
def __str__(self):
return str(self.file)
def applymap(self):
return self.file.applymap(float)
i = (input("Pick a DataSet= "))
df = Dataset(i)
df.read()
plt.show()
Run Code Online (Sandbox Code Playgroud) 我们有以下两个数据框
temp = pd.DataFrame(np.array([['I am feeling very well',1],['It is hard to believe this happened',0],
['What is love?',1], ['No new friends',0],
['I love this show',1],['Amazing day today',1]]),
columns = ['message','sentiment'])
temp_truncated = pd.DataFrame(np.array([['I am feeling very',1],['It is hard to believe',1],
['What is',1], ['Amazing day',1]]),
columns = ['message','cutoff'])
Run Code Online (Sandbox Code Playgroud)
我的想法是创建第三个 DataFrame 来表示 之间的内部联接temp,并temp_truncated通过查找以 / 开头的匹配项temp来包含以下字符串temp_truncated
期望的输出:
message sentiment cutoff
0 I am feeling very well 1 1
1 It is hard to believe this happened 0 …Run Code Online (Sandbox Code Playgroud)