Read..csv File and Find the Observations and Its Values

Pandas DataFrame: Playing with CSV files

Pandas DataFrame: Playing with CSV files

Deepak K Gupta (DAKSH)

Epitomize on Pandas DataFrame

Pandas DataFrame → Excel like Information in Memory
              my_dict = { 'proper noun' : ["a", "b", "c", "d", "e","f", "g"],
'historic period' : [20,27, 35, 55, eighteen, 21, 35],
'designation': ["VP", "CEO", "CFO", "VP", "VP", "CEO", "Dr."]}
              df = pd.DataFrame(my_dict)            

Pandas DataFrame → From Python Lexicon

Persisting the DataFrame into a CSV file

              df.to_csv('csv_example')            
              df_csv = pd.read_csv('csv_example')            

df_csv

Did you lot notice something unusual?

              df.to_csv('csv_example', index=False)            
              df_csv = pd.read_csv('csv_example')            

df_csv

Playing with Cavalcade Header

              df_csv = pd.read_csv('csv_example', header = 0)            
              df_csv = pd.read_csv('csv_example', header=[0,one,two])            

df_csv → with 3 rows as Header
              df_csv = pd.read_csv('csv_example', header=5)            

df_csv → Afterwards skipping 5 rows
              df_csv = pd.read_csv('csv_example', header=[1,2,5])            

df_csv → Multiple Row Headers

Customizing Column Names

              df_csv = pd.read_csv('csv_example', names=['a', 'b', 'c'])            

df_csv → with our own column names
              df_csv = pd.read_csv('csv_example', names=['a', 'b', 'c'], header=1)            

df_csv → With Customised Header
              df.to_csv('csv_example', index=Faux, header = Imitation)            
              df_csv = pd.read_csv('csv_example', names=['AGE', 'DESIGNATION', 'Proper name'])            

df_csv → With customised header

CSV to (Anything) Separated Value

              df.to_csv('csv_example', alphabetize=Imitation, sep=":")            
              df_csv = pd.read_csv('csv_example', sep=":")            

df_csv → with ":" as separator

Setting the Row Alphabetize

              df_csv.set_index('historic period')            

df_csv → Using 'age' as row index
              df_csv = pd.read_csv('csv_example', sep=":", index_col=ane)            

df_csv → with index_col = 1
              df_csv = pd.read_csv('csv_example', sep=":", index_col=[0,2])            

df_csv → index_col = [0,2]

If all rows are not required… Don't load them

              # Load Only 3 Rows
df_csv = pd.read_csv('csv_example', sep=":", nrows=3)

df_csv → Loading only three Rows

Skipping Empty Lines in CSV files

              df_csv = pd.read_csv('csv_example', skip_blank_lines=False, sep=":")            

jacksonthre1949.blogspot.com

Source: https://towardsdatascience.com/pandas-dataframe-playing-with-csv-files-944225d19ff

0 Response to "Read..csv File and Find the Observations and Its Values"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel