Thanks for joining me!
Good company in a journey makes the way seem shorter. — Izaak Walton

Thanks for joining me!
Good company in a journey makes the way seem shorter. — Izaak Walton

obj = Series([4, 7, -5, 3])
obj2 = Series([4, 7, -5, 3], index=['d', 'b', 'a', 'c'])
obj2[obj2 > 0]
obj2 * 2
'b' in obj2 (如果索引中存在 b,返回 True)
data = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada'],
'year': [2000, 2001, 2002, 2001, 2002],
'pop': [1.5, 1.7, 3.6, 2.4, 2.9]}
frame = DataFrame(data)
dict1 = { \
'timestamp' : str(timestamp), \
'guifei' : float(itemList[16]) \
}
buyDataList.append(dict1)
### use 'list of dict' to construct dataframe
buyDf = pd.DataFrame(buyDataList, columns=['timestamp' 'qita'])
a
## create df with list of tuple
data1 = []
for item in resList:
l1 = item.split(',')
l1.insert(0,str('sz002466'))
tu1 = tuple(l1)
data1.append(tu1)
df = pd.DataFrame(data1, columns=eastTableColumns)
a
## create df with list of list
df4 = pd.DataFrame([list6], columns=eastTableColumns)
a
### existing df append list as Series
tt7 = pd.Series(list1, index=list)
tt7.name = ('sz002407', '2016-08-02')
df3 = df3.append(tt7)
#### create df by list of list and combine df
arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),
np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])]
df = pd.DataFrame(np.random.randn(8, 4), index=arrays)
narr = [np.array(['bar', 'baz', 'foo', 'qux']),
np.array(['three', 'three', 'three', 'three'])]
l1 = [1,3,5,7]
l2 = [2,3,4,5]
l3 = [5,7,5,6]
l4 = [24,4,6,7]
alll = [l1,l2,l3,l4]
df1 = pd.DataFrame( alll , index=narr)
frames = [ df , df1 ]
res = pd.concat(frames)
dfl.loc['20130102':'20130104'] #### 选取 部分行
df.loc[:,['A', 'B'] ] #### 选取 A列和 B列的所有行
df.loc['20130102':'20130104' ,['A', 'B'] ] ### 行列都指定
s1.iloc[:3] ### 取前3行
s1.iloc[3] ### 取第 4 行
df1.iloc[1:5, 2:4] #### 1:5 是行序号, 2:4是列序号
df.ix[[('bar', 'two'), ('qux', 'on ')]] ### 圆括号里面的是组合行索引,索引包含2个值
de >df[(df.one >=1 ) & (df.one
de >df1.loc[ df1.Per == '-' , 'Per' ] = 0de>
dfwithnostop = dfndaylow[ ~dfndaylow[1].isin( dfstop1.drop_duplicates().tolist() ) ]
####pandas 取反符号是 ~
dfOne = selDf[start:end]
# get first value
code = dfOne['code'].get(0)
tstamp = dfOne['timestamp'].get(0)
price = float( dfOne['price'].get(0) )
amount = abs( int( dfOne['amount'].get(0) ) )
frame2['debt'] = 16.5 (如果原来没有'debt' 列,这个操作就增加了一列,默认值是16.5 )
frame2['eastern'] = frame2.state == 'Ohio'
(创建新的列,每个的值为一个判断语句的返回值(frame2.state == 'Ohio'))
del frame2['eastern'] (删除列)
vv = frame.T (转置完的类型还是 Dataframe )
df.head(3) (如果索引中存在 b,返回 True)
df.tail(3)
df2 = df.describe() (类型还是 Dataframe )([u'count', u'mean', u'std', u'min', u'25%', u'50%', u'75%', u'max'])
df.head(3) (如果索引中存在 b,返回 True)
df.tail(3)
kbdf = buy_df.copy()
sdf = sdf.sort(['date','time'])
sortedBdf = matchBuyDf.sort(['amount','price'], ascending=[False,True])
df2 = df.sort_values(by=[timestamp], ascending=[False] )
# 寻找满足条件的行的index(集合),然后使用 loc 函数匹配
t1 = bdf[ (bdf['date'] > lastSellDate) | ( (bdf['date'] == lastSellDate) & (bdf['time'] > lastSellTime) ) ].index
df.loc[t1, 'status'] = 2
# 如果是DF 中的单独一行,需要使用 “name”属性。
df.loc[sortedBdf.iloc[0].name,'status'] = 1
df = df[ (df['flag'] == sell_flag) | (df['flag'] == buy_flag) ]
# 选取 DF 中的某几列
df = df[list(df.columns[:7]) + list(df.columns[10:])]
df2[ [4 , 10, 14, 18, 22, 23 ] ]
# 遍历某个 DF,其中 sdf_row 是当前行的 series
for sell_df_index, sdf_row in sdf.iterrows():
sdf_row['price'] # series 方式
# 使用该函数读取文件
# mycols 是一个自定义的列表,其中包括 code, amount
# 通过 dtype 参数指定数据类型
df = pd.read_csv(pandasInputFile, sep=',', skiprows=5, index_col=False,
names=mycols, dtype={'code':np.object, 'amount':np.int16} )
## 如上,mycols可以是一个list,在dtype参数里面可以指定mycols中包含的列的数据类型
df2.to_csv('reffiles/stBasic.txt', sep='|', encoding='utf-8')
# df 中字符串的操作
df.loc[ df[1].str.startswith('6') , 1] = 'sh' + df[1].astype(str)
df2[[4,10]] = df2[[4,10]].applymap(lambda x : x.strip('%') ).apply( pd.to_numeric ) ### 去除字符串末尾的百分号,并且转换成数值类型
1、查找当前用户主目录下的所有文件:
下面两种方法都可以使用
$ find $HOME -print
$ find ~ -print$ find . -type f -perm 644 -exec ls -l {} \;
3、为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径;
$ find / -type f -size 0 -exec ls -l {} \;
4、查找/var/logs目录中更改时间在7日以前的普通文件,并在删除之前询问它们;
$ find /var/logs -type f -mtime +7 -ok rm {} \;
5、为了查找系统中所有属于root组的文件;
$find . -group root -exec ls -l {} \;
-rw-r--r-- 1 root root 595 10月 31 01:09 ./fie1
6、find命令将删除当目录中访问时间在7日以来、含有数字后缀的admin.log文件。
该命令只检查三位数字,所以相应文件的后缀不要超过999。先建几个admin.log*的文件 ,才能使用下面这个命令
$ find . -name "admin.log[0-9][0-9][0-9]" -atime -7 -ok
rm {} \;
? n
? n
? n
? n
7、为了查找当前文件系统中的所有目录并排序;
$ find . -type d | sort
8、为了查找系统中所有的rmt磁带设备;
$ find /dev/rmt -print
三、xargs
xargs – build and execute command lines from standard input
在使用find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。
find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。
在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高;
而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。
来看看xargs命令是如何同find命令一起使用的,并给出一些例子。
下面的例子查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件
#find . -type f -print | xargs file
./.kde/Autostart/Autorun.desktop: UTF-8 Unicode English text
./.kde/Autostart/.directory: ISO-8859 text\
......
在整个系统中查找内存信息转储文件(core dump) ,然后把结果保存到/tmp/core.log 文件中:
$ find / -name "core" -print | xargs echo "" >/tmp/core.log
上面这个执行太慢,我改成在当前目录下查找
#find . -name "file*" -print | xargs echo "" > /temp/core.log
# cat /temp/core.log
./file6
在当前目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限:
# ls -l
drwxrwxrwx 2 sam adm 4096 10月 30 20:14 file6
-rwxrwxrwx 2 sam adm 0 10月 31 01:01 http3.conf
-rwxrwxrwx 2 sam adm 0 10月 31 01:01 httpd.conf
# find . -perm -7 -print | xargs chmod o-w
# ls -l
drwxrwxr-x 2 sam adm 4096 10月 30 20:14 file6
-rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf
-rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf
用grep命令在所有的普通文件中搜索hostname这个词:
# find . -type f -print | xargs grep "hostname"
./httpd1.conf:# different IP addresses or hostnames and have them handled by the
./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames
on your
用grep命令在当前目录下的所有普通文件中搜索hostnames这个词:
# find . -name \* -type f -print | xargs grep "hostnames"
./httpd1.conf:# different IP addresses or hostnames and have them handled by the
./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames
on your
注意,在上面的例子中, \用来取消find命令中的*在shell中的特殊含义。
find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令。
四、find 命令的参数
下面是find一些常用参数的例子,有用到的时候查查就行了,像上面前几个贴子,都用到了其中的的一些参数,也可以用man或查看论坛里其它贴子有find的命令手册
1、使用name选项
文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用。
可以使用某种文件名模式来匹配文件,记住要用引号将文件名模式引起来。
不管当前路径是什么,如果想要在自己的根目录$HOME中查找文件名符合*.txt的文件,使用~作为 ‘pathname’参数,波浪号~代表了你的$HOME目录。
$ find ~ -name "*.txt" -print
想要在当前目录及子目录中查找所有的‘ *.txt’文件,可以用:
$ find . -name "*.txt" -print
想要的当前目录及子目录中查找文件名以一个大写字母开头的文件,可以用:
$ find . -name "[A-Z]*" -print
想要在/etc目录中查找文件名以host开头的文件,可以用:
$ find /etc -name "host*" -print
想要查找$HOME目录中的文件,可以用:
$ find ~ -name "*" -print 或find . -print
要想让系统高负荷运行,就从根目录开始查找所有的文件。
$ find / -name "*" -print
如果想在当前目录查找文件名以两个小写字母开头,跟着是两个数字,最后是.txt的文件,下面的命令就能够返回名为ax37.txt的文件:
$find . -name "[a-z][a-z][0--9][0--9].txt" -print
2、用perm选项
按照文件权限模式用-perm选项,按文件权限模式来查找文件的话。最好使用八进制的权限表示法。
如在当前目录下查找文件权限位为755的文件,即文件属主可以读、写、执行,其他用户可以读、执行的文件,可以用:
$ find . -perm 755 -print
还有一种表达方法:在八进制数字前面要加一个横杠-,表示都匹配,如-007就相当于777,-006相当于666
# ls -l
-rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf
-rw-rw-rw- 1 sam adm 34890 10月 31 00:57 httpd1.conf
-rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf
drw-rw-rw- 2 gem group 4096 10月 26 19:48 sam
-rw-rw-rw- 1 root root 2792 10月 31 20:19 temp
# find . -perm 006
# find . -perm -006
./sam
./httpd1.conf
./temp
-perm mode:文件许可正好符合mode
-perm +mode:文件许可部分符合mode
-perm -mode: 文件许可完全符合mode
3、忽略某个目录
如果在查找文件时希望忽略某个目录,因为你知道那个目录中没有你所要查找的文件,那么可以使用-prune选项来指出需要忽略的目录。在使用-prune选项时要当心,因为如果你同时使用了-depth选项,那么-prune选项就会被find命令忽略。
如果希望在/apps目录下查找文件,但不希望在/apps/bin目录下查找,可以用:
$ find /apps -path "/apps/bin" -prune -o -print
4、使用find查找文件的时候怎么避开某个文件目录
比如要在/usr/sam目录下查找不在dir1子目录之内的所有文件
find /usr/sam -path "/usr/sam/dir1" -prune -o -print find [-path ..] [expression] 在路径列表的后面的是表达式
-path “/usr/sam” -prune -o -print 是 -path “/usr/sam” -a -prune -o
-print 的简写表达式按顺序求值, -a 和 -o 都是短路求值,与 shell 的 && 和 || 类似如果 -path “/usr/sam” 为真,则求值 -prune , -prune 返回真,与逻辑表达式为真;否则不求值 -prune,与逻辑表达式为假。如果 -path “/usr/sam” -a -prune 为假,则求值 -print ,-print返回真,或逻辑表达式为真;否则不求值 -print,或逻辑表达式为真。
这个表达式组合特例可以用伪码写为
if -path "/usr/sam" then
-prune
else
-print
避开多个文件夹
find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print
圆括号表示表达式的结合。
\ 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。
查找某一确定文件,-name等选项加在-o 之后
#find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print
5、使用user和nouser选项
按文件属主查找文件,如在$HOME目录中查找文件属主为sam的文件,可以用:
$ find ~ -user sam -print
在/etc目录下查找文件属主为uucp的文件:
$ find /etc -user uucp -print
为了查找属主帐户已经被删除的文件,可以使用-nouser选项。这样就能够找到那些属主在/etc/passwd文件中没有有效帐户的文件。在使用-nouser选项时,不必给出用户名; find命令能够为你完成相应的工作。
例如,希望在/home目录下查找所有的这类文件,可以用:
$ find /home -nouser -print
6、使用group和nogroup选项
就像user和nouser选项一样,针对文件所属于的用户组, find命令也具有同样的选项,为了在/apps目录下查找属于gem用户组的文件,可以用:
$ find /apps -group gem -print
要查找没有有效所属用户组的所有文件,可以使用nogroup选项。下面的find命令从文件系统的根目录处查找这样的文件
$ find / -nogroup-print
7、按照更改时间或访问时间等查找文件
如果希望按照更改时间来查找文件,可以使用mtime,atime或ctime选项。如果系统突然没有可用空间了,很有可能某一个文件的长度在此期间增长迅速,这时就可以用mtime选项来查找这样的文件。
用减号-来限定更改时间在距今n日以内的文件,而用加号+来限定更改时间在距今n日以前的文件。
希望在系统根目录下查找更改时间在5日以内的文件,可以用:
$ find / -mtime -5 -print
为了在/var/adm目录下查找更改时间在3日以前的文件,可以用:
$ find /var/adm -mtime +3 -print
8、查找比某个文件新或旧的文件
如果希望查找更改时间比某个文件新但比另一个文件旧的所有文件,可以使用-newer选项。它的一般形式为:
newest_file_name ! oldest_file_name
其中,!是逻辑非符号。
查找更改时间比文件sam新但比文件temp旧的文件:
例:有两个文件
-rw-r--r-- 1 sam adm 0 10月 31 01:07 fiel
-rw-rw-rw- 1 sam adm 34890 10月 31 00:57 httpd1.conf
-rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf
drw-rw-rw- 2 gem group 4096 10月 26 19:48 sam
-rw-rw-rw- 1 root root 2792 10月 31 20:19 temp
# find -newer httpd1.conf ! -newer temp -ls
1077669 0 -rwxrwxr-x 2 sam adm 0 10月 31 01:01 ./httpd.conf
1077671 4 -rw-rw-rw- 1 root root 2792 10月 31 20:19 ./temp
1077673 0 -rw-r--r-- 1 sam adm 0 10月 31 01:07 ./fiel
查找更改时间在比temp文件新的文件:
$ find . -newer temp -print在/etc目录下查找所有的目录,可以用:
$ find /etc -type d -print
在当前目录下查找除目录以外的所有类型的文件,可以用:
$ find . ! -type d -print
在/etc目录下查找所有的符号链接文件,可以用
$ find /etc -type l -print
10、使用size选项
可以按照文件长度来查找文件,这里所指的文件长度既可以用块(默认单位block,512 bytes)来计量,也可以用字节来计量。以字节计量文件长度的表达形式为N c;以块计量文件长度只用数字表示即可。
在按照文件长度查找文件时,一般使用这种以字节表示的文件长度,在查看文件系统的大小,因为这时使用块来计量更容易转换。
在当前目录下查找文件长度大于1 M字节的文件:
$ find . -size +1000000c -print
在/home/apache目录下查找文件长度恰好为100字节的文件:
$ find /home/apache -size 100c -print
在当前目录下查找长度超过10块的文件(一块等于512字节):
$ find . -size +10 -print$ find . -size +200 -type f > ~/bigfile.txt查找大于100K,是普通文件(非目录)的文件列表,并保存结果到文件“~/bigfile.txt”中。
11、使用depth选项
在使用find命令时,可能希望先匹配所有的文件,再在子目录中查找。使用depth选项就可以使find命令这样做。这样做的一个原因就是,当在使用find命令向磁带上备份文件系统时,希望首先备份所有的文件,其次再备份子目录中的文件。
在下面的例子中, find命令从文件系统的根目录开始,查找一个名为CON.FILE的文件。
它将首先匹配所有的文件然后再进入子目录中查找。
$ find / -name "CON.FILE" -depth -print
12、使用mount选项
在当前的文件系统中查找文件(不进入其他文件系统),可以使用find命令的mount选项。
从当前目录开始查找位于本文件系统中文件名以XC结尾的文件:
$ find . -name "*.XC" -mount -print13、对选项“取非”
例子:
find /dev ! \( -type d -o -type c -o -type -b \)
上例中的感叹号(!)表示查找不符合指定条件(文件类型是 -b or -c or -d )的文件,比如 -f 的文件就会被打印出来
find . \( -name “*.h” -o -name “*.cpp” -o -name “*.cxx” -o -name “*.c” \) -follow > ~/tempfile4
tar cvf ~/6850code.tar -I ~/tempfile4
例子: 打印当前目录下所有文件,但skip 目录(perlscript )和目录(shellscript )下的文件
find . -name perlscript -prune -o -name shellscript -prune -o -print
find . -name “calcEepromCrc.c” -o -name perlscript -prune
合并,联合以及连接
http://pandas.pydata.org/pandas-docs/stable/merging.html
【
】
frames = [ df1, df2, df3 ]
Append
Merge(根据列的值,而非index,来进行合并)
【
】
Join(从两个可能index不相同的df中,把部分列合并到一起)
]]
���ָ�ʽ��
#include ��ʽһ
#include ��filename�� ��ʽ��
��ʽһ ��ʾ������ϵͳ��standard Ŀ¼���ҵ����ļ���
��ʽ�� ��ʾ������ϵͳ�� alternative Ŀ¼���ҵ����ļ���
l ����ʹ�þ���·����ָ���ļ�λ��
l ����ļ���ǰû��·�������Ȳ����û��ĵ�ǰĿ¼�����û�ҵ����ٲ��� standard Ŀ¼��
�����included ���ļ���Ҳ�� file include directive�� ����ЩҲ�ᱻ��ִ�С�
#ifdef
#ifndef
#endif
#ifdef �� #ifndef ��������Ϊ��ʼ��־���� #endif ���ǽ�����־��
������������������������Ƿ�compile��
��Щ������Ƕ��ʹ�á�
�����䣺
#define
您必须登录才能发表评论。