import pandas as pd import matplotlib.pyplot as plt Read data from Excel file df =…
- User
import pandas as pd import matplotlib.pyplot as plt
Read data from Excel file
df = pd.read_csv('smmh.csv')
Basic analysis
print("Basic Analysis:") print(df.describe())
Correlation analysis
print("\nCorrelation Analysis:") print(df.corr())
Visualization
Example: Age distribution
plt.figure(figsize=(8, 6)) plt.hist(df['Age'], bins=range(20, 31), edgecolor='black', alpha=0.7) plt.title('Age Distribution') plt.xlabel('Age') plt.ylabel('Count') plt.grid(True) plt.show()
- Assistant
It seems like you have a few lines of code here intended to load a dataset, perform some basic and correlation analysis, and visualize an 'Age' distribution. However, there are a couple of mistakes that need to be corrected:
-
The
pd.read_csv('smmh.csv')call indicates that you're trying to read a CSV file, not an Excel file. If your file is indeed in Excel format (like ), you need to use instead of .
-
- User
the data example "Timestamp,1. What is your age?,2. Gender,3. Relationship Status,4. Occupation Status,5. What type of organizations are you affiliated with?,6. Do you use social media?,7. What social media platforms do you commonly use?,8. What is the average time you spend on social media every day?,9. How often do you find yourself using Social media without a specific purpose?,10. How often do you get distracted by Social media when you are busy doing something?,11. Do you feel restless if you haven't used Social media in a while?,"12. On a scale of 1 to 5, how easily distracted are you?","13. On a scale of 1 to 5, how much are you bothered by worries?",14. Do you find it difficult to concentrate on things?,"15. On a scale of 1-5, how often do you compare yourself to other successful people through the use of social media?","16. Following the previous question, how do you feel about these comparisons, generally speaking?",17. How often do you look to seek validation from features of social media?,18. How often do you feel depressed or down?,"19. On a scale of 1 to 5, how frequently does your interest in daily activities fluctuate?","20. On a scale of 1 to 5, how often do you face issues regarding sleep?" 4/18/2022 19:18:47,21,Male,In a relationship,University Student,University,Yes,"Facebook, Twitter, Instagram, YouTube, Discord, Reddit",Between 2 and 3 hours,5,3,2,5,2,5,2,3,2,5,4,5 4/18/2022 19:19:28,21,Female,Single,University Student,University,Yes,"Facebook, Twitter, Instagram, YouTube, Discord, Reddit",More than 5 hours,4,3,2,4,5,4,5,1,1,5,4,5 4/18/2022 19:25:59,21,Female,Single,University Student,University,Yes,"Facebook, Instagram, YouTube, Pinterest",Between 3 and 4 hours,3,2,1,2,5,4,3,3,1,4,2,5 4/18/2022 19:29:43,21,Female,Single,University Student,University,Yes,"Facebook, Instagram",More than 5 hours,4,2,1,3,5,3,5,1,2,4,3,2 4/18/2022 19:33:31,21,Female,Single,University Student,University,Yes,"Facebook, Instagram, YouTube",Between 2 and 3 hours,3,5,4,4,5,5,3,3,3,4,4,1 4/18/2022 19:33:48,22,Female,Single,University Student,University,Yes,"Facebook, Twitter, Instagram, YouTube, Discord, Pinterest, TikTok",Between 2 and 3 hours,4,4,2,3,4,3,4,4,3,3,2,4 4/18/2022 19:36:12,21,Female,Married,University Student,University,Yes,"Facebook, Instagram, YouTube, Snapchat, TikTok",Between 3 and 4 hours,4,3,2,2,4,3,5,3,4,5,5,3 4/18/2022 19:36:17,21,Female,In a relationship,University Student,University,Yes,"Facebook, Instagram, YouTube",More than 5 hours,5,2,3,3,3,1,1,3,1,5,5,1 4/18/2022 19:39:36,21,Female,In a relationship,University Student,University,Yes,"Facebook, Instagram, YouTube",More than 5 hours,5,2,3,3,1,1,1,3,1,5,5,1 " give professioanl analysis
- Assistant
- User
give me professional analysis like feature extraction like relationship in data like if possible to add some column
- Assistant
- User
- Assistant
- User
Exception has occurred: ValueError time data "5-11-2022 19:06" doesn't match format "%m/%d/%Y %H:%M:%S", at position 243. You might want to try: - passing
formatif your strings have a consistent format; - passingformat='ISO8601'if your strings are all ISO8601 but not necessarily in exactly the same format; - passingformat='mixed', and the format will be inferred for each element individually. You might want to usedayfirstalongside this. File "C:\Users\ayelg\OneDrive\Bureau\illy\data.py", line 51, in df['Timestamp'] = pd.to_datetime(df['Timestamp']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: time data "5-11-2022 19:06" doesn't match format "%m/%d/%Y %H:%M:%S", at position 243. You might want to try: - passingformatif your strings have a consistent format; - passingformat='ISO8601'if your strings are all ISO8601 but not necessarily in exactly the same format; - passingformat='mixed', and the format will be inferred for each element individually. You might want to usedayfirstalongside this. - Assistant
The error indicates that there's a mismatch between the expected format of the datetime strings in your CSV file and the format that
pd.to_datetime()is trying to parse. The example error message suggests that the timestamp "5-11-2022 19:06" does not match the format"%m/%d/%Y %H:%M:%S". This is likely because the format in your file doesn't include seconds, and the date and time might be using a different delimiter than/.To fix the issue, you need to provide the correct format to the
pd.to_datetime()function, which corresponds to the format in your CSV file. From the error, it seems the format might be"%m-%d-%Y %H:%M"or"%d-%m-%Y %H:%M"depending on whether the first part is month or day. You'll need to verify the correct order based on your dataset.