python_使用
2016-06-13 15:00
477 查看
1、系统相关
!cmd Execute cmd in the system shell
output = !cmd args Run cmd and store the stdout in output
%alias alias_name cmd Define an alias for a system (shell) command
%bookmark Utilize IPython’s directory bookmarking system
%cd directory Change system working directory to passed directory
%pwd Return the current system working directory
%pushd directory Place current directory on stack and change to target directory
%popd Change to directory popped off the top of the stack
%dirs Return a list containing the current directory stack
%dhist Print the history of visited directories
%env Return the system environment variables as a dict
2、ipython定义类
class Message:
def __init__(self, msg):
self.msg = msg
def __repr__(self):
return 'Message: %s' % self.msg
3、类型转换
(1)rr.astype(np.int32)//类型转换
(2)string 转float
numeric_strings = np.array(['1.25', '-9.6', '42'], dtype=np.string_)
numeric_strings.astype(float)
array([ 1.25, -9.6 , 42. ])
4、array 并不copy
(1) arr_slice = arr[5:8] //相当于引用
arr_slice[1] = 12345
Out[59]: array([ 0, 1, 2, 3, 4, 12, 12345, 12, 8, 9])
In [60]: arr_slice[:] = 64
Out[61]: array([ 0, 1, 2, 3, 4, 64, 64, 64, 8, 9])
(2)拷贝:arr[5:8].copy()
5、numpy 保存数据
(1) numpy.save('test', var)
x = numpy.load('test.npy')
(2) 保存多个数据
numpy.savez('zdad.npz', a= arr, b= arr)
x = numpy.load('zdad.npz')
x['a'], x['b']
6、numpy 读取文件按
numpy.genfromtxt('world_alcohol.csv', delimiter = ',',dtype = 'U75', skip_header = True)、、delimiter 利用 ‘,’进行分割,u75:设置成unicode自字符,skip_header:跳过表的抬头
print (world_alcohol)
7、numpy
numpy.sum(aix=1), 每行求和
numpy.sum(aix=0), 每列求和
8、pandas 获取以 ‘g‘结尾的列
print(food_info.columns)
print(food_info.head(2))
col_names = food_info.columns.tolist()//获取表的列名
gram_columns = []
for c in col_names:
if c.endswith("(g)"):
gram_columns.append(c)
gram_df = food_info[gram_columns]
print(gram_df.head(3))
!cmd Execute cmd in the system shell
output = !cmd args Run cmd and store the stdout in output
%alias alias_name cmd Define an alias for a system (shell) command
%bookmark Utilize IPython’s directory bookmarking system
%cd directory Change system working directory to passed directory
%pwd Return the current system working directory
%pushd directory Place current directory on stack and change to target directory
%popd Change to directory popped off the top of the stack
%dirs Return a list containing the current directory stack
%dhist Print the history of visited directories
%env Return the system environment variables as a dict
2、ipython定义类
class Message:
def __init__(self, msg):
self.msg = msg
def __repr__(self):
return 'Message: %s' % self.msg
3、类型转换
(1)rr.astype(np.int32)//类型转换
(2)string 转float
numeric_strings = np.array(['1.25', '-9.6', '42'], dtype=np.string_)
numeric_strings.astype(float)
array([ 1.25, -9.6 , 42. ])
4、array 并不copy
(1) arr_slice = arr[5:8] //相当于引用
arr_slice[1] = 12345
Out[59]: array([ 0, 1, 2, 3, 4, 12, 12345, 12, 8, 9])
In [60]: arr_slice[:] = 64
Out[61]: array([ 0, 1, 2, 3, 4, 64, 64, 64, 8, 9])
(2)拷贝:arr[5:8].copy()
5、numpy 保存数据
(1) numpy.save('test', var)
x = numpy.load('test.npy')
(2) 保存多个数据
numpy.savez('zdad.npz', a= arr, b= arr)
x = numpy.load('zdad.npz')
x['a'], x['b']
6、numpy 读取文件按
numpy.genfromtxt('world_alcohol.csv', delimiter = ',',dtype = 'U75', skip_header = True)、、delimiter 利用 ‘,’进行分割,u75:设置成unicode自字符,skip_header:跳过表的抬头
print (world_alcohol)
7、numpy
numpy.sum(aix=1), 每行求和
numpy.sum(aix=0), 每列求和
8、pandas 获取以 ‘g‘结尾的列
print(food_info.columns)
print(food_info.head(2))
col_names = food_info.columns.tolist()//获取表的列名
gram_columns = []
for c in col_names:
if c.endswith("(g)"):
gram_columns.append(c)
gram_df = food_info[gram_columns]
print(gram_df.head(3))
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法