如果我们在 Series.value_counts() 方法中设置 normalize=True,就可以得到 Series 对象中所有独特元素的相对频率。
importpandasaspdimportnumpyasnpdf = pd.DataFrame({'X': [1, 2, 3, np.nan, 3],
'Y': [4, np.nan, 8, np.nan, 3]})
print("DataFrame:")
print(df)
relative_counts=df["X"].value_counts(normalize=True)
print("Relative Frequencies of elements of X column:")
print(relative_counts)
输出:
DataFrame:
X Y
0 1.0 4.0
1 2.0 NaN
2 3.0 8.0
3 NaN NaN
4 3.0 3.0
Frequencies of elements of X column:
3.0 0.50
2.0 0.25
1.0 0.25
Name: X, dtype: float64
Country Item Type Sales Channel Order Priority
0 Tuvalu Baby Food Offline H
1 East Timor Meat Online L
2 Norway Baby Food Online L
3 Portugal Baby Food Online H
4 Honduras Snacks Online L
5 New Zealand Fruits Online H
6 Moldova Personal Care Online L
Country Sales Channel Order Priority
0 Tuvalu Offline H
1 East Timor Online L
2 Norway Online L
3 Portugal Online H
4 Honduras Online L
5 New Zealand Online H
6 Moldova Online L
Tuvalu Baby Food Offline H
0 East Timor Meat Online L
1 Norway Baby Food Online L
2 Portugal Baby Food Online H
3 Honduras Snacks Online L
4 New Zealand Fruits Online H
5 Moldova Personal Care Online L
<?php
$string= base64_encode ('Your string values are encoded');
echo"1.Here is the encoded function value in a machine readable format = ".$string."<br>";
echo"2.The function decodes the formerly encoded string value"."<br>".base64_decode($string);
?>
输出:
1.Here is the encoded function value in a machine readable
format = WW91ciBzdHJpbmcgdmFsdWVzIGFyZSBlbmNvZGVk
2. The function decodes the formerly encoded string value
Your string values are encoded.
示例代码显示了 base64_decode() 函数如何在一个简单的场景中工作。
为了对编码数据进行解码,程序为变量赋值,然后与解码函数一起使用。
而输出表明 base64_decode() 如何将数据转换回用户可读格式。
PHP Base64_decode 函数示例代码 2
<?php
//The following variable is assigned with a string set
$string="HELLO--こんにちは--你好";
//string contains bilingual text
//base64 is used to encode the data first into the $enco variable
$enco= base64_encode ($string);
//finally the base64_decode functionis used to decode the encoded value
$deco= base64_decode ($enco);
echo$deco;
?>