Conteúdo do Curso
Pandas First Steps
Pandas First Steps
TXT Files
To read text files in pandas
, you can use the same function, pd.read_csv()
. However, to ensure the text file is read correctly, it's essential to use an additional parameter called sep
, which stands for separator or delimiter in the text.
If your text file doesn't have a header row containing column names, set the header
parameter to None
. Doing so informs pandas
not to treat the first row as column names.
Note
To use a new line as the separator in a file, which is common in text files, set
sep='\r'
. Here,'\r'
stands for a carriage return, which is a special character used to indicate a new line.
Swipe to show code editor
- Read the TXT file into a DataFrame.
- Display only the first line (the first row of
text_data
) on your screen.
Obrigado pelo seu feedback!
TXT Files
To read text files in pandas
, you can use the same function, pd.read_csv()
. However, to ensure the text file is read correctly, it's essential to use an additional parameter called sep
, which stands for separator or delimiter in the text.
If your text file doesn't have a header row containing column names, set the header
parameter to None
. Doing so informs pandas
not to treat the first row as column names.
Note
To use a new line as the separator in a file, which is common in text files, set
sep='\r'
. Here,'\r'
stands for a carriage return, which is a special character used to indicate a new line.
Swipe to show code editor
- Read the TXT file into a DataFrame.
- Display only the first line (the first row of
text_data
) on your screen.
Obrigado pelo seu feedback!