Analyze Data/Python Libraries
pandas-4. read_csv, unique, to_csv, file upload, file download
Naranjito
2021. 6. 22. 16:30
- read_csv
- sep : Separator
- names : List of column names to use.
- header : To use as the column names, and the start of the data. If column names are passed explicitly then the behavior is identical to header=None.
- low_memory : It results mixed type inference, so set False to ensure no mixed type.
columns=['user_id', 'item_id', 'rating', 'timestamp']
df=pd.read_csv('./u.data',sep='\t', names=columns, low_memory=False)
df.head()
>>>
user_id item_id rating timestamp
0 196 242 3 881250949
1 186 302 3 891717742
2 22 377 1 878887116
- unique
Return unique values.
pd.unique(pd.Series([1,3,1,5]))
>>>
array([1, 3, 5])
- to_csv
Write object to a csv file.
1. First way, using colab : download it to my local via colab.
import pandas as pd
from google.colab import files
uploaded = files.upload()
df_100=df[:100]
df_100.to_csv('df_100.csv')
files.download('df_100.csv')
2. Second way
df_result=df.to_csv('df.csv')