我在python 2.7中使用sqlite创建了一个数据库,并将数据加载到pandas数据帧中,如下所示。我想要做的是我想将结果打印为“7月最温暖的城市是:伊斯坦布尔,安卡拉,伊兹密尔,布尔萨”。我用Python编写的代码如下:
else {
if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
URL url2 = new URL((thumb[j]));
Bitmap bimage = BitmapFactory.decodeStream(url2
.openConnection().getInputStream());
shareImage();
Toast.makeText(getApplicationContext(),
"Saving to Favorites", Toast.LENGTH_LONG)
.show();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
private void shareImage() {
Intent share = new Intent(Intent.ACTION_SEND);
// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");
// Make sure you put example png image named myImage.png in your
// directory
String bimage = Environment.getExternalStorageDirectory()
+ thumb[j];
File imageFileToShare = new File(bimage);
Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image!"));
}
}
答案 0 :(得分:1)
您可以加入来自df["city"]
的元素数组
In [53]: print "The cities warmest in July are: %s" % ', '.join(df["city"].values)
The cities warmest in July are: Istanbul, Ankara, Izmir, Bursa
', '.join(df["city"].values)
- 这将返回以逗号分隔的字符串。
此外,您可以使用pd.read_sql()
或pd.read_sql_query
直接将sql结果读取到数据帧。
In [54]: pd.read_sql("SELECT city FROM weather INNER JOIN cities ON name = city"
....: " WHERE warm_month = 'July'", con)
Out[54]:
city
0 Istanbul
1 Ankara
2 Izmir
3 Bursa