Amberwest's Note


  • Home

  • Tags

  • Categories

  • Archives

  • Search

oracle序列

Posted on 2019-04-14 | In 数据库
创建序列

oracle可以用sequence关键字创建序列,语法如下:

1
2
3
4
5
6
7
8
create sequence [user.]sequence_name
increment by n
start with n
maxvalue | nomaxvalue
minvalue | nominvalue
cycle | nocycle
cache | nocache
order | noorader
Read more »

mysql中的isnull、ifnull和nullif

Posted on 2019-03-10 | Edited on 2019-03-12 | In 数据库

关于ifnull和nullif两个函数刚看的时候有点混淆,所以记录一下。

IFNULL(*expr1*,*expr2*):如果expr1不为NULL则返回expr1,否则返回expr2。

1
2
3
4
5
6
7
8
select ifnull(1, 'yes');
> 1
select ifnull(0, 'yes');
> 0
select ifnull(null, 'yes');
> yes
select ifnull(1/0, 'yes');
> yes
Read more »

通过值列表选择pandas DataFrame中的行

Posted on 2019-03-07 | Edited on 2019-03-11 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:Use a list of values to select rows from a pandas dataframe [duplicate]

如下:

1
2
3
4
5
6
7
8
9
10
11
12
import pandas as pd

df = pd.DataFrame({'A' : [5,6,3,4], 'B' : [1,2,3, 5]})

df
"""
A B
0 5 1
1 6 2
2 3 3
3 4 5
"""
Read more »

保存DataFrame到csv文件

Posted on 2019-03-06 | Edited on 2019-03-11 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:Pandas writing dataframe to csv file,如题,将dataframe写入到csv文件可以使用to_csv方法。

1
2
3
df.to_csv(
['path_or_buf=None', "sep=','", "na_rep=''", 'float_format=None', 'columns=None', 'header=True', 'index=True', 'index_label=None', "mode='w'", 'encoding=None', 'compression=None', 'quoting=None', 'quotechar=\'"\'', "line_terminator='\\n'", 'chunksize=None', 'tupleize_cols=None', 'date_format=None', 'doublequote=True', 'escapechar=None', "decimal='.'"],
)

解释几个常用的参数,详细信息查看官方文档:

  • path_or_buf:路径,string类型。df保存为csv文件的路径,相对路径或者绝对路径。
  • sep:分隔符,默认是“,”,可以自由设置。
  • na_rep:空值替换,默认为空字符串。
  • float_format:float类型数字的格式设置。如float_format=”%.2f”。
  • columns:序列。选择要写入的列。
  • header:默认为True(Series默认为False),可以是string和list。列名。
  • index:默认True,即行名。
  • mode:默认为w,即写模式。
  • encoding:编码方式。
  • chunksize:一次写入行数。
Read more »

删除DataFrame中某列值为NaN的记录/行

Posted on 2019-03-05 | Edited on 2019-03-10 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:How to drop row of Pandas DataFrame whose value in certain columns is NaN

如题。我们先创建数据

1
2
3
4
5
6
7
8
9
10
11
import pandas as pd
import numpy as np

input_rows = [[1,2,3], [2,3,4], [np.nan, 2, np.nan, 5], [np.nan, 5, 7]]
df = pd.DataFrame(input_rows, columns=['a', 'b', 'c', 'd'])

out: a b c d
0 1.0 2 3.0 NaN
1 2.0 3 4.0 NaN
2 NaN 2 NaN 5.0
3 NaN 5 7.0 NaN
Read more »

改变pandas中列的数据类型

Posted on 2019-03-05 | Edited on 2019-03-10 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:change data type of columns in pandas,如何将列的数据转为合适的类型,如将下例中数字从string类型转为float。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import pandas as pd

a = [['a', '1.2', '4.2'], ['b', '70', '0.03'], ['x', '5', '0']]
df = pd.DataFrame(a, columns=['aa', 'bb', 'cc'])

# df
'''
aa bb cc
0 a 1.2 4.2
1 b 70 0.03
2 x 5 0
'''

df.dtypes
'''
aa object
bb object
cc object
dtype: object
'''
Read more »

添加一行数据到DataFrame

Posted on 2019-03-04 | Edited on 2019-03-10 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:Add one row to pandas DataFrame,要求一行一行地添加数据到已有的空白DataFrame中。

1
2
3
4
5
import pandas as pd
import numpy as np

# 创建空白DataFrame
df = pd.DataFrame(columns=['lib', 'qty1', 'qty2'])

1)使用loc

1
2
3
for i in range(4):
df.loc[i] = [np.random.randint(-1, 1) for n in range(3)]
# df.loc[i] = 5 添加一条数据都为5的记录
Read more »

如何改变DataFrame列的顺序

Posted on 2019-03-03 | Edited on 2019-03-10 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:How to change the orders of DataFrame columns

还是用之前的数据:

1
2
3
4
5
import pandas as pd

df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
'B': 'one one two three two two one three'.split(),
'C': np.arange(8), 'D': np.arange(8) * 2})
Read more »

获取DataFrame的行数

Posted on 2019-03-03 | Edited on 2019-03-10 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:How do I get a row count of a Pandas DataFrame

如下:

1
2
3
4
5
6
7
8
9
10
import pandas as pd

df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
'B': 'one one two three two two one three'.split(),
'C': np.arange(8), 'D': np.arange(8) * 2})
# 方法一:使用shape
row_count, column_count = df.shape

# 方法二:使用len函数
row_count = len(df)
Read more »

选择DataFrame中的多列数据

Posted on 2019-03-03 | Edited on 2019-03-10 | In 今天你学pandas了吗

这是系列文章,我会按照stackoverflow上pandas相关问题投票数排序进行整理学习。不学习是会变咸鱼的~

原问题:selecting multiple columns in pandas dataframe,如题,选择DataFrame中的多列数据。

假设原始数据如下:

1
2
3
4
5
6
import pandas as pd
import numpy as np

df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
'B': 'one one two three two two one three'.split(),
'C': np.arange(8), 'D': np.arange(8) * 2})
Read more »
12…8

amberwest

学习笔记

78 posts
8 categories
120 tags
E-Mail
© 2019 amberwest
Powered by Hexo v3.7.1
|
Theme — NexT.Mist v6.2.0