Pandas DataFrame.values属性
Pandas DataFrame.values属性返回给定DataFrame的Numpy表示。
语法:DataFrame.values
参数:None
返回:数组
示例1
使用DataFrame.values属性返回给定DataFrame的numpy表示。
# importing pandas as pd
import pandas as pd
# Creating the DataFrame
df = pd.DataFrame({'Weight':[45, 88, 56, 15, 71],
'Name':['Sam', 'Andrea', 'Alex', 'Robin', 'Kia'],
'Age':[14, 25, 55, 8, 21]})
# Print the DataFrame
print(df)
输出:
现在,我们将使用DataFrame.values属性返回给定DataFrame的numpy表示。
# return the numpy representation of
# this dataframe
result = df.values
# Print the result
print(result)
输出:
正如我们在输出中看到的,DataFrame.values属性成功地返回了给定DataFrame的numpy表示。
示例2
使用DataFrame.values属性返回给定DataFrame的numpy表示。
# importing pandas as pd
import pandas as pd
# Creating the DataFrame
df = pd.DataFrame({"A":[12, 4, 5, None, 1],
"B":[7, 2, 54, 3, None],
"C":[20, 16, 11, 3, 8],
"D":[14, 3, None, 2, 6]})
# Print the DataFrame
print(df)
输出:
现在,我们将使用DataFrame.values属性返回给定DataFrame的numpy表示。
# return the numpy representation of
# this dataframe
result = df.values
# Print the result
print(result)
输出:
正如我们在输出中看到的,DataFrame.values属性成功地返回了给定DataFrame的numpy表示。