python笔记:3.2.1.1pandas数据结构_DataFrame3

# -*- coding: utf-8 -*-
"""
Created on Wed May 22 17:27:32 2019

@author: User
"""

import pandas as pd

jddf=pd.read_csv('data\stock.csv',header=None,
                 names=['id',
                'time',
                'code',
                'open_p',
                'close_p',
                'low_p',
                'vol',
                'high_p',
                'col'])

print(jddf.head(10))
print('1-----------------')
print(jddf.info())

print('\n重新设置索引:')
jddfsetind=jddf.set_index(jddf['id'])
print(jddfsetind.head())

print('\n导出csv...:')
jddf.to_csv('data\out.csv')
print('\n导出完成。')

print('\n导出excel...(需要openpyxl包):')
jddf.to_csv('data\out.xlsx')
print('\n导出完成。好牛啊,太快了!')

运行:

   id      time    code  open_p  close_p  low_p       vol  high_p      col
0   1  20130902  600028    4.41     4.43   4.37  17275.39    4.41   392662
1   2  20130903  600028    4.41     4.46   4.40  19241.84    4.45   434177
2   3  20130904  600028    4.44     4.49   4.42  20106.30    4.47   451470
3   4  20130905  600028    4.47     4.48   4.42  15582.48    4.47   349997
4   5  20130906  600028    4.46     4.52   4.45  19101.41    4.50   425777
5   6  20130909  600028    4.50     4.66   4.50  47976.94    4.61  1046700
6   7  20130910  600028    4.61     4.67   4.55  43045.16    4.65   931737
7   8  20130911  600028    4.66     4.78   4.65  54751.36    4.69  1164934
8   9  20130912  600028    4.63     4.68   4.55  45201.83    4.64   980581
9  10  20130913  600028    4.63     4.65   4.54  25158.60    4.58   548881
1-----------------
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3982 entries, 0 to 3981
Data columns (total 9 columns):
id         3982 non-null int64
time       3982 non-null int64
code       3982 non-null int64
open_p     3982 non-null float64
close_p    3982 non-null float64
low_p      3982 non-null float64
vol        3982 non-null float64
high_p     3982 non-null float64
col        3982 non-null int64
dtypes: float64(5), int64(4)
memory usage: 280.1 KB
None

重新设置索引:
    id      time    code  open_p  close_p  low_p       vol  high_p     col
id                                                                        
1    1  20130902  600028    4.41     4.43   4.37  17275.39    4.41  392662
2    2  20130903  600028    4.41     4.46   4.40  19241.84    4.45  434177
3    3  20130904  600028    4.44     4.49   4.42  20106.30    4.47  451470
4    4  20130905  600028    4.47     4.48   4.42  15582.48    4.47  349997
5    5  20130906  600028    4.46     4.52   4.45  19101.41    4.50  425777

导出csv...:

导出完成。

导出excel...(需要openpyxl包):

导出完成。好牛啊,太快了!
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值