我需要创建一个testset = pd.read_csv('my_dataset_path')
对象,以便在更大的代码块中使用。
我有一个数据集作为DataFrame读入,名为" testset。"
str
然后我想结合两个列,Latitude和Longitude,来自" testset"到一个u = u"""Latitude,Longitude
42.357778,-71.059444
39.952222,-75.163889
25.787778,-80.224167
30.267222, -97.763889"""
对象。
我希望它看起来像这样:
Lat = testset['Latitude'].astype(str) #creates a series
Long = testset['Longitude'].astype(str) #creates a series
Lat_str=Lat.str.cat(sep=' ') #coerces a 'str' object
Long_str=Long.str.cat(sep=' ') #coerces a 'str' object
u= Lat_str,Long_str
但是当我尝试以下内容时:
str
我只是从两个function ScrollManager() {
let startYCoord;
function getScrollDiff(event) {
let delta = 0;
switch (event.type) {
case 'mousewheel':
delta = event.wheelDelta ? event.wheelDelta : -1 * event.deltaY;
break;
case 'touchstart':
startYCoord = event.touches[0].clientY;
break;
case 'touchmove': {
const yCoord = event.touches[0].clientY;
delta = yCoord - startYCoord;
startYCoord = yCoord;
break;
}
}
return delta;
}
function getScrollDirection(event) {
return getScrollDiff(event) >= 0 ? 'UP' : 'DOWN';
}
function blockScrollOutside(targetElement, event) {
const { target } = event;
const isScrollAllowed = targetElement.contains(target);
const isTouchStart = event.type === 'touchstart';
let doScrollBlock = !isTouchStart;
if (isScrollAllowed) {
const isScrollingUp = getScrollDirection(event) === 'UP';
const elementHeight = targetElement.scrollHeight - targetElement.offsetHeight;
doScrollBlock =
doScrollBlock &&
((isScrollingUp && targetElement.scrollTop <= 0) ||
(!isScrollingUp && targetElement.scrollTop >= elementHeight));
}
if (doScrollBlock) {
event.preventDefault();
}
}
return {
blockScrollOutside,
getScrollDirection,
};
}
const scrollManager = ScrollManager();
const testBlock = document.body.querySelector('.test');
function handleScroll(event) {
scrollManager.blockScrollOutside(testBlock, event);
}
window.addEventListener('scroll', handleScroll);
window.addEventListener('mousewheel', handleScroll);
window.addEventListener('touchstart', handleScroll);
window.addEventListener('touchmove', handleScroll);
对象中获取一个元组。
我不想列出最后一个&#39; str&#39;中的每个项目。对象&#34; u&#34;因为列有超过1000个条目。有没有办法简化这个以获得所需的结果?我尝试了其他形式的变形&#34; u&#34;但它永远不会是正确的。
答案 0 :(得分:1)
由于您使用pandas,最简单的方法是使用to_csv()
:
u = testset[['Latitude' ,'Longitude']].to_csv(index=False)
print(u)
输出:
Latitude,Longitude
42.357778,-71.059444
39.952222,-75.163889
25.787778,-80.22416700000001
30.267221999999997,-97.763889
如果您想避开30.267221999999997,
,请回合:
u = testset[['Latitude' ,'Longitude']].round(6).to_csv(index=False)
print(u)
输出:
Latitude,Longitude
42.357778,-71.059444
39.952222,-75.163889
25.787778,-80.224167
30.267222,-97.763889