datanalysisref.txt 956 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # read data file in R
  2. df = data.table::fread('/path/to/file.csv')
  3. # read data file in Python
  4. df = pd.read_csv('/path/to/file.csv')
  5. # list column names in R
  6. names(df)
  7. colnames(df)
  8. # list column names in Python
  9. df.columns
  10. # list row names in R
  11. rownames(df)
  12. # list row names in Python
  13. df.index
  14. # list number of columns in R
  15. ncol(df)
  16. # list number of rows in R
  17. nrow(df)
  18. # list dimensions of dataframe in R
  19. dim(df)
  20. # list dimensions of dataframe in Python
  21. df.shape
  22. # access a column of a dataframe in Python
  23. df['colname'].head(4)
  24. # access a row of a dataframe in Python
  25. df.loc[3].head(4)
  26. df.iloc[3].head(4)
  27. # list first/last n rows of a dataframe in R
  28. head(df, n)
  29. tail(df, n)
  30. # list first/last n rows of a dataframe in Python
  31. df.head(n)
  32. df.tail(n)
  33. # describe dataframe in R
  34. summary(df)
  35. # describe dataframe in Python
  36. df.describe()
  37. # data types of attributes in Python
  38. df.info()
  39. # correlation of attributes in the data
  40. df.corr(method='pearson')