小编Jos*_*una的帖子

在pandas数据帧中将字符串2.90K转换为2900或5.2M到5200000

在pandas数据帧中处理数据需要一些帮助.我们非常欢迎任何帮助.

我有CSV格式的OHCLV数据.我已将文件加载到pandas dataframe中.

如何将音量列从2.90K转换为2900或将5.2M转换为5200000.该列可以包含数千K的K和数百万的M.

import pandas as pd

file_path = '/home/fatjoe/UCHM.csv'
df = pd.read_csv(file_path, parse_dates=[0], index_col=0)
df.columns = [
"closing_price", 
"opening_price", 
"high_price", 
"low_price",
"volume",
"change"]

df['opening_price'] = df['closing_price']
df['opening_price'] = df['opening_price'].shift(-1)
df = df.replace('-', 0)
df = df[:-1]
print(df.head())

Console:
 Date
 2016-09-23          0
 2016-09-22      9.60K
 2016-09-21     54.20K
 2016-09-20    115.30K
 2016-09-19     18.90K
 2016-09-16    176.10K
 2016-09-15     31.60K
 2016-09-14     10.00K
 2016-09-13      3.20K
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

9
推荐指数
3
解决办法
4899
查看次数

使用Angular UI Carousel进行`跟踪$ index'的问题

当使用分页时,索引跟踪的$ index不会从零开始

我用角度ui bootsrap创建了一个旋转木马.由于我加载了如此多的图像(超过1,000),我使用过滤器在分页中显示500张图片.

.filter('pages', function () {
    return function (input, currentPage, pageSize) {
        if (angular.isArray(input)) {
            var start = (currentPage - 1) * pageSize;
            var end = currentPage * pageSize;
            return input.slice(start, end);
        }
    };
})
Run Code Online (Sandbox Code Playgroud)

控制器:

self.currentPage = 1;
self.itemsPerPage = 500;
self.maxSize = 10;

//imagesUrls is response.data from http call
angular.forEach(imagesUrls, function (parent) {
    var date = uibDateParser.parse(parent.fileCreationTime, 'M/d/yyyy 
                     hh:mm:ss a');
    // fill our slide arrays with urls
    // model update here
    self.slides.push({
        image: parent.fileName,
        time: date, …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-ng-repeat angular-ui-bootstrap

5
推荐指数
1
解决办法
759
查看次数