Surya_from_1627

ADAP2

Jul 14th, 2026 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. df = pd.DataFrame({
  4. 'A': [10, 20, 30],
  5. 'B': [1, 2, 3]
  6. })
  7. print(df)
  8. -----------------------------
  9. df = pd.DataFrame({
  10. 'A': [10, 20, 30]})
  11. df['A_squared'] = df['A'].apply(lambda x: x**2)
  12. print(df['A_squared'])
  13. --------------------------------
  14. # Sum of A and B row-wise
  15. df = pd.DataFrame({
  16. 'A': [10, 20, 30],
  17. 'B': [1, 2, 3]
  18. })
  19. df['Row_Sum'] = df.apply(lambda row: row['A'] + row['B'], axis=1)
  20. print(df['Row_Sum'])
  21. -------------------------------
  22. df_csv = pd.read_csv('data.csv')
  23. print(df_csv)
  24. -------------------------------
  25. df_excel = pd.read_excel('data.xlsx')
  26. -------------------------------
  27. df_json = pd.read_json('data.json')
  28. -------------------------------
  29. import sqlite3
  30. conn = sqlite3.connect('data.db')
  31. df_sql = pd.read_sql_query("SELECT * FROM my_table", conn)
  32. ---------------------------------
  33. import pandas as pd
  34. df = pd.DataFrame({
  35. 'ID': [1, 2, 4],
  36. 'Marks': [85, 90, 78]
  37. })
  38. df.describe() # Summary statistics
  39. -------------------------------
  40. df.mean()
  41. -------------------------------
  42. df.median() # Median
  43. -------------------------------
  44. df.std() # Standard deviation
  45. -------------------------------
  46. df.var() # Variance
  47. -------------------------------
  48. df.min(), df.max() # Min, Max
  49. -------------------------------
  50. df.corr() # Correlation matrix
  51. -------------------------------
  52. import pandas as pd
  53.  
  54. # Sample DataFrame with Category
  55. df3 = pd.DataFrame({
  56. 'Item': ['Apple', 'Banana', 'Carrot',
  57. 'Banana','Apple', 'Carrot'],
  58. 'Category': ['Fruit', 'Fruit', 'Vegetable',
  59. 'Fruit', 'Fruit', 'Vegetable'],
  60. 'Quantity': [10, 5, 8, 6, 7, 3],
  61. 'Price': [15, 10, 12, 10, 15, 12]
  62. })
  63.  
  64. print(df3)
  65. -------------------------------
  66. grouped = df3.groupby('Category').sum()
  67. print(grouped)
  68. -------------------------------
  69. df1 = pd.DataFrame({
  70. 'ID': [1, 2, 3],
  71. 'Name': ['Alice', 'Bob', 'Charlie']
  72. })
  73.  
  74. df2 = pd.DataFrame({
  75. 'ID': [1, 2, 4],
  76. 'Marks': [85, 90, 78]
  77. })
  78. df_combined = pd.concat([df1, df2], axis=0) # Row-wise
  79. print(df_combined)
  80. df_merged = pd.concat([df1, df2], axis=1) # Column-wise
  81. print(df_merged)
  82. -------------------------------
Advertisement
Add Comment
Please, Sign In to add comment