我想spcify x和y轴在Python中的数据帧中绘制数据.
例如,我在数据帧中有四列.这是我的代码.
df.plot(x=df['a'], y=df['b'], label=df['c'])
Run Code Online (Sandbox Code Playgroud)
它抛出一个错误说:这些值来自'b'列.
"KeyError:'[500.8 567.2 487.2 444.4 1371.6 714.4 1157.4
476.8 345.4 \n 1076.4 881.8 813. 452.6 663.6 606.8 469.2 805.2 487.4 \n 497.8 440. 127. 68.6 1494.2 716.4 1447. 97.8 110. \n 1126.4 1422.8 92.4 1000.8]不在指数'"
感谢您的帮助.
我想绘制一个带有标签的散点图。但是,这些标签是重叠的。如何增强外观,以便更好地查看数字?另外,我的数字是整数,但它以浮点数显示标签值。我想知道为什么。
期待收到您的回音。
这是我的代码:
col = df['type'].map({'a':'r', 'b':'b', 'c':'y'})
ax = df.plot.scatter(x='x', y='y', c=col)
df[['x','y','id']].apply(lambda x: ax.text(*x),axis=1)
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用mongodb java驱动程序通过聚合函数编写组.
这是数据库的文档结构.
{ "_id" : ObjectId("58819bd9f16a7802523bc077"), "Date" : "12/19/2016", "Time" : "4:15:00", "Temperature" : 65.5, "User" : "A", "ThermalComfort" : -1, "settingID" : ObjectId("58819bd6f16a7802523bbdc5") }
{ "_id" : ObjectId("58819bd9f16a7802523bc078"), "Date" : "12/19/2016", "Time" : "4:30:00", "Temperature" : 65.25, "User" : "A", "ThermalComfort" : -1, "settingID" : ObjectId("58819bd6f16a7802523bbdc5") }
Run Code Online (Sandbox Code Playgroud)
我想按"日期"和"时间"分组,仅投影ThermalComfort.我的预期输出为:{date = 12/19/16,time = 0:00:00,listOfTC = [2,1]}.listOfTC是由Array中的每个读数组成的列表:(例如[-1,-1])
这是我写的代码.
AggregateIterable<Document> iterable = themalComfortProfileCollection.aggregate(Arrays.asList(
new Document("$group", new Document("_id", "$Date" + "$Time").append("count", new Document("$sum", 1))),
new Document("$project", new Document("comfortIndex", "$ThermalComfort"))));
Run Code Online (Sandbox Code Playgroud)
但是,如果我打印出文档,我将获得null文档.
for (Document doc …Run Code Online (Sandbox Code Playgroud) 我试图在Python中绘制散点图,颜色代码存储在数据框的"颜色"列中.我得到无效的RGBA参数错误.
这是我的代码和数据:
df.plot.scatter(x='x', y='y', c='color')
id x type color y
0 109 570.4 ha r 500.8
1 110 632.4 ha r 567.2
2 111 399.4 of b 487.2
3 112 250.2 of b 444.4
Run Code Online (Sandbox Code Playgroud)
...
我在使用 Java 搜索 mongodb 中的 ISODate 字段时遇到问题。我想找到完全匹配的日期。
以下是我查询第一个集合并获取 ISODate 字段“Timestamp”的方法。一旦我得到这个日期,我想搜索具有相同“时间戳”值的另一个集合。
FindIterable<Document> docList = thermalComfortCollection.find();
for(Document doc: docList) {
String ts = doc.get("Timestamp").toString();
System.out.println(ts);
Run Code Online (Sandbox Code Playgroud)
...
我正在格式化 ISODate,因为它以我想要搜索的不同格式返回日期。因此,我将其转换为这种模式“yyyy-MM-dd HH:mm:ss”
final DateTimeFormatter inputFormat =
DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy");
// The parsed date
final ZonedDateTime parsed = ZonedDateTime.parse(ts, inputFormat);
// The output format
final DateTimeFormatter outputFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String date = outputFormat.format(parsed);
Run Code Online (Sandbox Code Playgroud)
我找不到如何为 ISODate 类型编写精确匹配语句,因此我同时输入 gte 和 lte 条件来获得精确匹配..!
BasicDBObject query = new BasicDBObject("Timestamp", //
new BasicDBObject("$gte", date).append("$lte", date));
System.out.println(query);
Run Code Online (Sandbox Code Playgroud)
并且查询不起作用。你能给我任何评论我的代码的哪一部分是错误的吗?
我想绘制一个带有 x 和 y 轴的散点图,其中 x 轴分组。x轴有三种类型(例如h、o、c),可以通过ID列来识别。y 轴将具有每个 ID 的平均值。
这是示例数据:
id sum mean color type
0 109 2852 5.301115 r h
1 110 3162 5.877323 r h
2 111 1997 3.711896 b o
Run Code Online (Sandbox Code Playgroud)
Y 轴将是“平均”列值,X 轴将是分组“id”值。当我运行下面的代码时,它会生成错误:
File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:4279)
File "pandas\src\hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13742)
File "pandas\src\hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13696)
KeyError: 'type'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
df.set_index('type', inplace=True)
...
col = df['type'].map({'h':'r', 'o':'b', 'c':'y'})
ax = df.plot.scatter(x='type', y='mean', c=col)
Run Code Online (Sandbox Code Playgroud) 我有一个带有三个参数的函数。这是标题。
def count_ones(num, total_bits, group_size):
Run Code Online (Sandbox Code Playgroud)
我正在尝试将此功能应用于数据列。但这并没有返回我的预期。有人可以帮我解决这个问题吗?total_bits为60,group_size为12。
df['events'] = df['data'].apply(count_ones, args =(60, 12))
Run Code Online (Sandbox Code Playgroud)