[英]How to load a csv file into pandas to use it in a data frame
I am a beginner who is having trouble loading csv files into pandas dataframe.我是一名初学者,无法将 csv 文件加载到 pandas dataframe 中。
The code which I am trying to run in a jupyter notebook is:我试图在 jupyter notebook 中运行的代码是:
df_census = pd.read_csv('census.csv')
Then I have created a function which accepts the dataframe as a function parameter:然后我创建了一个 function 接受 dataframe 作为 function 参数:
def explore_df(df):
df.show()
But I am getting error while calling the function但是我在调用 function 时遇到错误
explore_df(df_census)
The error message is:错误信息是:
NameError
Traceback (most recent call last)
<ipython-input-11-e557e519fd3d> in <module>
----> 1 explore_df(df_census)
NameError: name 'df_census' is not defined
Not sure what show() does.不确定 show() 是做什么的。 If you would like to see what was loaded.如果您想查看已加载的内容。 Just print it.只需打印它。
import pandas as pd
df_census = pd.read_csv('census.csv')
def explore_df(df):
#df.show()
print(df)
explore_df(df_census)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.